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]
}
相关推荐
smj2302_796826523 分钟前
解决leetcode第3883题统计满足数位和数组的非递减数组数目
python·算法·leetcode
田梓燊20 分钟前
leetcode 56
java·算法·leetcode
2301_8035545226 分钟前
三大编程语言(Python/Go/C++)项目启动全解析
c++·python·golang
_深海凉_43 分钟前
LeetCode热题100-最长公共前缀
算法·leetcode·职场和发展
im_AMBER2 小时前
Leetcode 152 被围绕的区域 | 岛屿数量
数据结构·算法·leetcode·深度优先·广度优先·图搜索算法
吕司2 小时前
LeetCode Hot Code——最大子数组和
数据结构·算法·leetcode
XiYang-DING3 小时前
【LeetCode】144. 二叉树的前序遍历
算法·leetcode·职场和发展
6Hzlia3 小时前
【Hot 100 刷题计划】 LeetCode 215. 数组中的第K个最大元素 | C++ 快速选择与堆排序题解
c++·算法·leetcode
小白菜又菜3 小时前
Leetcode 3070. Count Submatrices with Top-Left Element and Sum Less Than k
算法·leetcode·职场和发展
会编程的土豆3 小时前
【数据结构与算法】拓扑排序2
数据结构·算法·leetcode