Golang | Leetcode Golang题解之第63题不同路径II

题目:

题解:

Go 复制代码
func uniquePathsWithObstacles(obstacleGrid [][]int) int {
    n, m := len(obstacleGrid), len(obstacleGrid[0])
    f := make([]int, m)
    if obstacleGrid[0][0] == 0 {
        f[0] = 1
    }
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            if obstacleGrid[i][j] == 1 {
                f[j] = 0
                continue
            }
            if j - 1 >= 0 && obstacleGrid[i][j-1] == 0 {
                f[j] += f[j-1]
            }
        }
    }
    return f[len(f)-1]
}
相关推荐
Miraitowa_cheems3 小时前
LeetCode算法日记 - Day 102: 不相交的线
数据结构·算法·leetcode·深度优先·动态规划
Miraitowa_cheems3 小时前
LeetCode算法日记 - Day 101: 最长公共子序列
数据结构·算法·leetcode·深度优先·动态规划
玖剹5 小时前
二叉树递归题目(一)
c语言·c++·算法·leetcode
沧澜sincerely5 小时前
BFS & 图论【各种题型+对应LeetCode习题练习】
leetcode·图论·广度优先
不穿格子的程序员5 小时前
从零开始写算法——二分-寻找旋转排序数组中的最小值
数据结构·算法·leetcode·二分查找
小白程序员成长日记5 小时前
2025.11.13 力扣每日一题
算法·leetcode·职场和发展
HotCoffee-GPS8 小时前
Golang学习笔记:定时crontab
golang
_fairyland9 小时前
数据结构 力扣 练习
数据结构·考研·算法·leetcode
橘颂TA9 小时前
【剑斩OFFER】算法的暴力美学——山脉数组的蜂顶索引
算法·leetcode·职场和发展·c/c++
博语小屋10 小时前
力扣11.盛水最多的容器(medium)
算法·leetcode·职场和发展