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();
    }
};
相关推荐
tachibana220 分钟前
hot100 数组中的第K个最大元素(215)
java·数据结构·算法·leetcode
txzrxz29 分钟前
单调队列讲解
数据结构·c++·算法·单调队列
WWTYYDS_6661 小时前
JsonCpp超详细使用教程
c++
Joey_friends1 小时前
指纹authenticate流程图
android·java·c++
小小晓.1 小时前
C++小白记:C风格字符串和数组用法
c语言·开发语言·c++
cpp_25012 小时前
P1540 [NOIP 2010 提高组] 机器翻译
数据结构·c++·算法·队列·noip·洛谷题解
晚笙coding2 小时前
LeetCode 98:验证二叉搜索树 —— 从局部判断到全局范围约束的递归思想
算法·leetcode·职场和发展
咕白m6252 小时前
通过 C++ 写入数据到 Excel 文档
c++·后端
兰令水3 小时前
hot100【acm版】【2026.7.21打卡-java版本】
java·开发语言·算法·leetcode·面试
qz5zwangzihan13 小时前
题解:Atcoder Beginner Contest abc467 F - Email Scheduling Optimization
c++·贪心·atcoder·平衡树·abc467·abc467_f·fhq-treap