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();
    }
};
相关推荐
lclin_20205 小时前
VS2010兼容|C++系统全能监控工具(彩色界面+日志带单位+完整版)
c++·windows·系统监控·vs2010·编程实战
鹿角片ljp6 小时前
最长回文子串(LeetCode 5)详解
算法·leetcode·职场和发展
paeamecium8 小时前
【PAT甲级真题】- Cars on Campus (30)
数据结构·c++·算法·pat考试·pat
UrSpecial8 小时前
从零实现C++轻量线程池
c++·线程池
chh5638 小时前
C++--模版初阶
c语言·开发语言·c++·学习·算法
会编程的土豆10 小时前
01背包与完全背包详解
开发语言·数据结构·c++·算法
hetao173383710 小时前
2026-04-12~14 hetao1733837 的刷题记录
c++·算法
智者知已应修善业11 小时前
【51单片机4位数循环小数位移数值位移】2023-6-9
c++·经验分享·笔记·算法·51单片机
王璐WL11 小时前
【C++】string,vector和list对比
c++·list
不爱吃炸鸡柳12 小时前
算法复杂度从入门到精通:时间与空间复杂度全解析
开发语言·c++·算法