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]
}
相关推荐
We་ct11 分钟前
LeetCode 114. 二叉树展开为链表:详细解题思路与 TS 实现
前端·数据结构·算法·leetcode·链表·typescript
追随者永远是胜利者19 分钟前
(LeetCode-Hot100)461. 汉明距离
java·算法·leetcode·职场和发展·go
努力学算法的蒟蒻23 分钟前
day90(2.19)——leetcode面试经典150
算法·leetcode·面试
踩坑记录33 分钟前
leetcode hot100 22. 括号生成 medium 递归回溯
leetcode
样例过了就是过了35 分钟前
LeetCode热题100 缺失的第一个正数
数据结构·算法·leetcode
样例过了就是过了38 分钟前
LeetCode热题100 除了自身以外数组的乘积
数据结构·算法·leetcode
v_for_van10 小时前
力扣刷题记录7(无算法背景,纯C语言)
c语言·算法·leetcode
We་ct13 小时前
LeetCode 105. 从前序与中序遍历序列构造二叉树:题解与思路解析
前端·算法·leetcode·链表·typescript
王老师青少年编程14 小时前
2020年信奥赛C++提高组csp-s初赛真题及答案解析(选择题11-15)
c++·题解·真题·初赛·信奥赛·csp-s·提高组