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