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();
    }
};
相关推荐
青少儿编程课堂2 小时前
威佐夫博弈(双堆取子游戏)解析
c++·python·算法·bfs·信息学竞赛
辰烨chenye6 小时前
LeetCode Hot 100 题解 · 普通数组篇
算法·leetcode·职场和发展
辰烨chenye10 小时前
LeetCode Hot 100 题解 · 二分篇
java·算法·leetcode
Keven_1111 小时前
算法札记:ACM适用的很骚的C++语法(持续更新)
开发语言·c++
mengzhi啊11 小时前
QPluginLoader 动态 DLL 插件版,支持插件之间通信,广播。请求和应答
c++·qt
老赵的博客14 小时前
c++ QT之动态库加载问题
c++·qt
(Charon)14 小时前
【C++】定时器进阶:使用最小堆管理定时任务
c++·算法
hansang_IR14 小时前
【题解】 [省选联考 2021 A/B 卷] 卡牌游戏
c++·算法
lzx_00215 小时前
C++11(一)
开发语言·c++·算法
带多刺的玫瑰16 小时前
Leecode#26刷题之删除有序数组中的重复项
数据结构·算法·leetcode