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]
}
相关推荐
在风中的意志1 小时前
[数据库SQL] [leetcode-584] 584. 寻找用户推荐人
数据库·sql·leetcode
毅炼1 小时前
hot100打卡——day08
java·数据结构·算法·leetcode·深度优先
DICOM医学影像4 小时前
15. Go-Ethereum测试Solidity ERC20合约 - Go-Ethereum调用合约方法
开发语言·后端·golang·区块链·智能合约·以太坊·web3.0
我要用代码向我喜欢的女孩表白6 小时前
对象存储路径文件1TB以上文件比对,go语言
ios·golang·xcode
leoufung7 小时前
LeetCode 67. Add Binary:从面试思路到代码细节
算法·leetcode·面试
无限进步_7 小时前
【C语言】循环队列的两种实现:数组与链表的对比分析
c语言·开发语言·数据结构·c++·leetcode·链表·visual studio
linsa_pursuer8 小时前
最长连续序列
java·数据结构·算法·leetcode
POLITE39 小时前
Leetcode 54.螺旋矩阵 JavaScript (Day 8)
javascript·leetcode·矩阵
巴塞罗那的风9 小时前
golang协程泄漏排查实战
开发语言·后端·golang
only-qi9 小时前
LeetCode 148. 排序链表
算法·leetcode·链表