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]
}
相关推荐
福大大架构师每日一题9 小时前
go-zero v1.9.3 版本更新:一致性哈希负载均衡、gRPC优化、链路追踪修复、ORM完善等重要提升
golang·负载均衡·哈希算法
努力学算法的蒟蒻11 小时前
day27(12.7)——leetcode面试经典150
算法·leetcode·面试
CoderYanger12 小时前
动态规划算法-子序列问题(数组中不连续的一段):28.摆动序列
java·算法·leetcode·动态规划·1024程序员节
有时间要学习13 小时前
面试150——第二周
数据结构·算法·leetcode
小白程序员成长日记16 小时前
2025.12.03 力扣每日一题
算法·leetcode·职场和发展
元亓亓亓16 小时前
LeetCode热题100--20. 有效的括号--简单
linux·算法·leetcode
熊猫_豆豆16 小时前
LeetCode 49.字母异位组合 C++解法
数据结构·算法·leetcode
小武~18 小时前
Leetcode 每日一题C 语言版 -- 234 basic calculator
linux·c语言·leetcode
小白程序员成长日记18 小时前
2025.12.02 力扣每日一题
数据结构·算法·leetcode
吃着火锅x唱着歌18 小时前
LeetCode 3583.统计特殊三元组
算法·leetcode·职场和发展