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]
}
相关推荐
退休倒计时3 小时前
【每日一题】LeetCode 53. 最大子数组和 TypeScript
数据结构·算法·leetcode·typescript
张忠琳5 小时前
【Go 1.26.4】Golang Channel 深度解析
开发语言·后端·golang
洛水水6 小时前
【力扣100题】86.柱状图中最大的矩形
算法·leetcode·职场和发展
洛水水7 小时前
【力扣100题】81.寻找两个正序数组的中位数
数据结构·算法·leetcode
张忠琳8 小时前
【Go 1.26.4】Golang Map 深度解析
开发语言·后端·golang
洛水水8 小时前
【力扣100题】85.每日温度
算法·leetcode·职场和发展
Kurisu_红莉栖8 小时前
力扣56合并区间
算法·leetcode
开源Z9 小时前
LeetCode 135 · 分发糖果:两次扫描,先左后右取最大
算法·leetcode
退休倒计时9 小时前
【每日一题】LeetCode 19. 删除链表的倒数第 N 个结点 TypeScript
leetcode·链表·typescript
怪兽学LLM12 小时前
LeetCode 21 合并两个有序链表:彻底理解虚拟头节点(Dummy)套路
python·leetcode·链表