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();
    }
};
相关推荐
ShineWinsu12 分钟前
对于Qt:QFormLayout常见属性以及方法的解析
开发语言·c++·qt·面试·客户端·表单·qformlayout
kyle~44 分钟前
嵌入式 SoC 系统
linux·c++·嵌入式·计算系统
ashiho2 小时前
【LeetCode hot 100】3. 无重复字符的最长子串 (三种解法)
java·数据结构·后端·算法·leetcode·滑动窗口
爱写Bug的浮游4 小时前
C++移动构造真的比拷贝快吗
c++·性能优化
Aaa西红柿鸡蛋4 小时前
网络协议分析实验:基于 UDP 广播模型的 C/S 通信设计与实现
c++
青少儿编程课堂5 小时前
蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级:扫描线与线段树求矩形面积并解析
c++·python·算法·bfs·信息学竞赛
Pniubi13 小时前
01背包类问题-力扣416.分割等和子集
算法·leetcode·职场和发展
文丑颜不良啊1 天前
LeetCode3041~3060题目解析
java·leetcode
eggwyw1 天前
C++ union 的一种妙用法
开发语言·c++
文丑颜不良啊1 天前
LeetCode3101~3120题目解析
java·leetcode