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();
    }
};
相关推荐
潼心1412o1 小时前
C++初阶(长期更新)第5讲:类和对象(中)
开发语言·c++
weixin_307779131 小时前
C++代码实现MATLAB中的normalize函数功能
开发语言·c++·算法·matlab
(Charon)1 小时前
【C++面试】手写String类:同时实现拷贝构造与移动构造
c++·算法
程序员老陆1 小时前
通过std::unique_ptr初始化std::shared_ptr
开发语言·c++
CoderYanger2 小时前
A.每日一题:1614. 括号的最大嵌套深度
java·程序人生·算法·leetcode·面试·学习方法
Xin7703 小时前
LeetCode 230. 二叉搜索树中第 K 小的元素(迭代中序遍历 + 栈)
leetcode
西西弗Sisyphus3 小时前
Qt6 实现 会动的界面像物理世界一样
c++·qt
UIU1143 小时前
头文件可以防什么错?运用头文件做声明
c++·学习·c#
Navigator_Z4 小时前
LeetCode //C - 1283. Find the Smallest Divisor Given a Threshold
c语言·算法·leetcode
by209994 小时前
list:迭代器与资源管理实现的综合叙述(下)
数据结构·c++·笔记·list