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();
    }
};
相关推荐
203号居民3 小时前
LeetCode hot 100 — 141. 环形链表2
算法·leetcode·链表
玖玥拾4 小时前
LeetCode 202 快乐数
算法·leetcode
码匠许师傅5 小时前
【设计模式精讲】14.外观模式(Facade)
c++·设计模式·uml·外观模式
Tim_105 小时前
【LeetCode】29、两数相除
算法·leetcode·职场和发展
xxwxx__7 小时前
C++ list 深度解析:从使用原理到模拟实现
开发语言·c++·list
Chester_19997 小时前
CSP202303C.LDAP
开发语言·c++·蓝桥杯·stl
j7~8 小时前
【C++】《unordered系列关联式容器以及哈希底层、哈希冲突、闭散列与开散列完整解析》
c++·哈希算法·开散列·闭散列·unordered_map·unordered_set·哈希底层结构
lvwangshu8 小时前
P6534 [COCI 2015/2016 #1] UZASTOPNI 等差树列 题解
动态规划·图论·题解·性质题
2402_882893868 小时前
封装红黑树实现map和set —— 从源码到模拟实现
c++·set·map
神仙别闹10 小时前
基于C++ MFC 实现的智慧公交系统
开发语言·c++·mfc