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]
}
相关推荐
203号居民19 小时前
LeetCode hot 100 —41. 缺失的第一个正数
数据结构·算法·leetcode
evans在进步21 小时前
LeetCode 322:零钱兑换——Java 动态规划详解
java·leetcode·动态规划
Tisfy1 天前
LeetCode 3471.找出最大的几近缺失整数:三种情况判断
算法·leetcode·题解·分类讨论
码农大叔的博客1 天前
golang示例:switch
开发语言·后端·golang
青 春 记 忆1 天前
LeetCode 121. 买卖股票的最佳时机|Python 解法详解
python·算法·leetcode
rannn_1111 天前
【力扣hot100】二叉树专题
算法·leetcode·职场和发展
圣殿骑士-Khtangc1 天前
Go面试核心考点之GMP调度器源码级深度解析
golang
Navigator_Z1 天前
LeetCode //C - 1203. Sort Items by Groups Respecting Dependencies
c语言·算法·leetcode
Scabbards_2 天前
面试Leetcode - Heap 堆
java·leetcode·面试
ValhallaCoder2 天前
Leetcode-hot100(2026.08.17)
python·算法·leetcode