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]
}
相关推荐
夏鹏今天学习了吗19 小时前
【LeetCode热题100(47/100)】路径总和 III
算法·leetcode·职场和发展
smj2302_7968265219 小时前
解决leetcode第3721题最长平衡子数组II
python·算法·leetcode
m0_6265352019 小时前
力扣题目练习 换水问题
python·算法·leetcode
一匹电信狗19 小时前
【LeetCode_160】相交链表
c语言·开发语言·数据结构·c++·算法·leetcode·stl
·白小白21 小时前
力扣(LeetCode) ——118.杨辉三角(C++)
c++·算法·leetcode
std787921 小时前
Rust 与 Go – 比较以及每个如何满足您的需求
开发语言·golang·rust
仰泳的熊猫1 天前
LeetCode:207. 课程表
数据结构·c++·算法·leetcode
水冗水孚1 天前
双指针算法在实际开发中的具体应用之代码Review文章字符串的片段分割
算法·leetcode
Qiuner1 天前
《掰开揉碎讲编程-长篇》重生之哈希表易如放掌
数据结构·算法·leetcode·力扣·哈希算法·哈希·一文读懂
007php0071 天前
猿辅导Java面试真实经历与深度总结(二)
java·开发语言·python·计算机网络·面试·职场和发展·golang