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();
    }
};
相关推荐
海石1 小时前
1563分的简单题,可能就简单在能被暴力AC
算法·leetcode
海石1 小时前
1400分的dp汗流浃背之【交替子数组计数】
算法·leetcode
2023自学中2 小时前
C++ 内存追踪器
linux·c++
退休倒计时5 小时前
【每日一题】LeetCode 437. 路径总和 III TypeScript
算法·leetcode·typescript
tachibana25 小时前
hot100 翻转二叉树(226)
java·数据结构·算法·leetcode
兰令水5 小时前
leecodecode【面试150】【2026.7.9打卡-java版本】
java·数据结构·leetcode·面试·职场和发展
DogDaoDao6 小时前
【GitHub】 LLVM Project 深度解析:现代编译器基础设施的基石
java·c++·python·程序员·github·编译器·llvm
KuaCpp7 小时前
C++进程(下)
c++
来一碗刘肉面7 小时前
C++中的引用语法
c++·算法
杜子不疼.7 小时前
【Qt初识】工程起步:项目创建、代码解读与对象树
数据库·c++·qt