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]
}
相关推荐
TracyCoder1234 小时前
LeetCode Hot100(46/100)——74. 搜索二维矩阵
算法·leetcode·矩阵
im_AMBER4 小时前
Leetcode 119 二叉树展开为链表 | 路径总和
数据结构·学习·算法·leetcode·二叉树
苏荷水5 小时前
万字总结LeetCode100(持续更新...)
java·算法·leetcode·职场和发展
TracyCoder1237 小时前
LeetCode Hot100(50/100)——153. 寻找旋转排序数组中的最小值
算法·leetcode·职场和发展
化学在逃硬闯CS7 小时前
Leetcode110.平衡二叉树
数据结构·c++·算法·leetcode
爱coding的橙子7 小时前
Day87:2.12:leetcode 动态规划8道题,用时3h
算法·leetcode·动态规划
努力学算法的蒟蒻8 小时前
day84(2.12)——leetcode面试经典150
算法·leetcode·面试
程序员酥皮蛋8 小时前
hot 100 第二十三题 23.反转链表
数据结构·算法·leetcode·链表
TracyCoder1238 小时前
LeetCode Hot100(51/100)——155. 最小栈
数据结构·算法·leetcode