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();
    }
};
相关推荐
Shadow(⊙o⊙)13 分钟前
Linux网络部分——TCP服务端、客户端架构分析多进程、多线程、线程池
c++·tcp/ip·架构
zh路西法31 分钟前
【3D SLAM源码解读系列】(四) GTSAM与iSAM2——从回环约束到位姿图优化
c++·slam·gtsam·pgo·isam2
ZC跨境爬虫32 分钟前
LeetCode 88. 合并两个有序数组(双指针详解 + Java Python 实现)
java·python·算法·leetcode
Nil20835 分钟前
leetcode 238除了自身以外数组的乘积
数据结构·算法·leetcode
土司大王36 分钟前
LeetCode hot100——最长连续序列
数据结构·算法·leetcode
01二进制代码漫游日记1 小时前
C++基础入门速通
java·开发语言·c++
tudousisi2221 小时前
二维费用01背包
c++
2601_956121971 小时前
高精度问题
c++
橙橙笔记1 小时前
C++的学习第三部分
开发语言·c++·学习
君君思密达1 小时前
LeetCode Hot 100 题目详解-滑动窗口
算法·leetcode·职场和发展