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();
    }
};
相关推荐
alphaTao15 分钟前
LeetCode 每日一题 2026/1/12-2026/1/18
python·算法·leetcode
sin_hielo17 分钟前
leetcode 2943
数据结构·算法·leetcode
明洞日记2 小时前
【CUDA手册002】CUDA 基础执行模型:写出第一个正确的 Kernel
c++·图像处理·算法·ai·图形渲染·gpu·cuda
程序员-King.2 小时前
day134—快慢指针—环形链表(LeetCode-141)
算法·leetcode·链表·快慢指针
Swift社区2 小时前
LeetCode 376 摆动序列
算法·leetcode·职场和发展
oioihoii2 小时前
程序员如何系统入门Vibe Coding?
c++
C+++Python2 小时前
C++类型判断
开发语言·c++
张张努力变强3 小时前
C++类和对象(一):inline函数、nullptr、类的定义深度解析
开发语言·前端·jvm·数据结构·c++·算法
oioihoii3 小时前
C++线程编程模型演进:从Pthread到jthread的技术革命
java·开发语言·c++
Morwit4 小时前
*【力扣hot100】 448. 找到所有数组中消失的数字
数据结构·算法·leetcode