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();
    }
};
相关推荐
怎么没有名字注册了啊24 分钟前
查找成绩(数组实现)
c++·算法
AI+程序员在路上2 小时前
QT6中Combo Box与Combo BoxFont 功能及用法
c++·qt
L_09072 小时前
【Algorithm】Day-4
c++·算法·leetcode
代码充电宝2 小时前
LeetCode 算法题【简单】20. 有效的括号
java·算法·leetcode·面试·职场和发展
海琴烟Sunshine2 小时前
leetcode 119. 杨辉三角 II python
算法·leetcode·职场和发展
煜3642 小时前
C++异常与智能指针
开发语言·c++
光头闪亮亮3 小时前
ZBar 环境搭建与快速入门指南
c++
闭着眼睛学算法3 小时前
【双机位A卷】华为OD笔试之【模拟】双机位A-新学校选址【Py/Java/C++/C/JS/Go六种语言】【欧弟算法】全网注释最详细分类最全的华子OD真题题解
java·c语言·javascript·c++·python·算法·华为od
玉夏3 小时前
【每日算法C#】爬楼梯问题 LeetCode
算法·leetcode·c#
卿摆摆3 小时前
【C++】string的模拟实现
开发语言·c++