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 分钟前
LeetCode hoot 100 -- 和为K的子数组
算法·leetcode·职场和发展
_深海凉_14 分钟前
LeetCode热题100-最长递增子序列
算法·leetcode·职场和发展
codeejun25 分钟前
每日一Go-55、分布式 ID 生成(雪花算法 / Segment / Redis / DB)
数据库·分布式·golang
Tomhex9 小时前
Go容易出错的地方总结
golang
py有趣14 小时前
力扣热门100题之不同路径
算法·leetcode
_日拱一卒15 小时前
LeetCode:25K个一组翻转链表
算法·leetcode·链表
techdashen15 小时前
Go 标准库 JSON 包迎来重大升级:encoding/json/v2 实验版来了
开发语言·golang·json
小欣加油15 小时前
leetcode2078 两栋颜色不同且距离最远的房子
数据结构·c++·算法·leetcode·职场和发展
我真不是小鱼15 小时前
cpp刷题打卡记录30——轮转数组 & 螺旋矩阵 & 搜索二维矩阵II
数据结构·c++·算法·leetcode
帅小伙―苏16 小时前
力扣42接雨水
前端·算法·leetcode