C++ | Leetcode C++题解之第63题不同路径II

题目:

题解:

cpp 复制代码
class Solution {
public:
    int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
        int n = obstacleGrid.size(), m = obstacleGrid.at(0).size();
        vector <int> f(m);

        f[0] = (obstacleGrid[0][0] == 0);
        for (int i = 0; i < n; ++i) {
            for (int 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.back();
    }
};
相关推荐
程序员爱德华2 小时前
Python与C++:异同点对比
c++·python
普通攻击往后拉2 小时前
Leetcode 206. 反转链表
算法·leetcode·链表
888CC++5 小时前
C语言与C++的区别:从面向过程到面向对象
java·c语言·c++
Darkwanderor6 小时前
Linux系统编程实战项目:模拟实现shell
linux·c++
himobrinehacken7 小时前
揭秘Windows程序启动的神秘之旅
c++·安全
库玛西7 小时前
C++ 运行时多态 :核心总结与原理图解
c语言·c++·笔记
Byron Loong8 小时前
【C++】重定向是什么
开发语言·c++
hansang_IR9 小时前
【题解】LC:Z 算法(Z Algorithm)
c++·算法·字符串
橘子汽水1689 小时前
Leetcode 230,98:二叉搜索树中第K小的元素,验证二叉搜索树
算法·leetcode·职场和发展
霍霍的袁11 小时前
【C++】模板从入门到进阶(函数模板 + 类模板 + 特化 + 分离编译)
开发语言·c++·visual studio