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]
}
相关推荐
CoderYanger8 小时前
动态规划算法-简单多状态dp问题:15.买卖股票的最佳时机含冷冻期
开发语言·算法·leetcode·动态规划·1024程序员节
尋有緣8 小时前
力扣1069-产品销售分析II
leetcode·oracle·数据库开发
CoderYanger8 小时前
递归、搜索与回溯-FloodFill:33.太平洋大西洋水流问题
java·算法·leetcode·1024程序员节
尋有緣11 小时前
力扣2292-连续两年有3个及以上的订单产品
leetcode·oracle·数据库开发
CoderYanger11 小时前
动态规划算法-斐波那契数列模型:2.三步问题
开发语言·算法·leetcode·面试·职场和发展·动态规划·1024程序员节
sin_hielo11 小时前
leetcode 2211
数据结构·算法·leetcode
CoderYanger11 小时前
动态规划算法-简单多状态dp问题:16.买卖股票的最佳时机含手续费
开发语言·算法·leetcode·动态规划·1024程序员节
songtaiwu12 小时前
golang开发日常注意
开发语言·数据库·golang
java修仙传12 小时前
力扣hot100:最大子数组和
数据结构·算法·leetcode