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 小时前
C++_队列编码实例,从末端添加对象,同时把头部的对象剔除掉,中的队列长度为设置长度NUM_OBJ
java·c++·算法
Jayden_Ruan2 小时前
C++逆向输出一个字符串(三)
开发语言·c++·算法
liulun2 小时前
Skia如何渲染 Lottie 动画
c++·动画
点云SLAM3 小时前
C++ 常见面试题汇总
java·开发语言·c++·算法·面试·内存管理
YuTaoShao4 小时前
【LeetCode 每日一题】1277. 统计全为 1 的正方形子矩阵
算法·leetcode·矩阵
野犬寒鸦4 小时前
力扣hot100:相交链表与反转链表详细思路讲解(160,206)
java·数据结构·后端·算法·leetcode
阿昭L4 小时前
leetcode两数之和
算法·leetcode
UnnamedOrange5 小时前
ROS2 配置 linter 的代码格式化工具为 clang-format
c++·cmake
Lris-KK5 小时前
【Leetcode】高频SQL基础题--1164.指定日期的产品价格
sql·leetcode
Dobby_055 小时前
【面试题】C++系列(一)
c++·面经