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();
    }
};
相关推荐
xiaoye-duck7 分钟前
《C++ 工具库实战》高性能日志 spdlog:从基础使用到工程化封装
c++·第三方库
重生之小比特15 分钟前
【算法拾光】前缀和|连续的子数组和 + 和相同的二元子数组
算法·leetcode·哈希算法
努力努力再努力wz21 分钟前
【Lua入门系列】从 C++ 迭代器到 Lua 迭代器:一文深入理解 Lua 有状态以及无状态迭代器与泛型for、闭包、ipairs、pairs 和 next
开发语言·c++·lua
Pniubi25 分钟前
力扣 102二叉树的层序遍历(广度优先搜索)
leetcode·宽度优先
一去不复返的通信er26 分钟前
力扣15:盛最多水的容器
算法·leetcode
努力实干29 分钟前
第二阶段 · 第 7 课:C++ 多线程与线程安全
开发语言·c++·安全
Navigator_Z29 分钟前
LeetCode //C - 1309. Decrypt String from Alphabet to Integer Mapping
c语言·算法·leetcode
文丑颜不良啊1 小时前
LeetCode1281~1300题目解析
java·leetcode
小菜要扣篮2 小时前
Ubuntu 下使用 vscode 打开 C++ 项目后,无法通过 F12 定位到定义问题解决
c++·vscode·ubuntu
wuminyu2 小时前
JVM规范学习总结:class执行性能差异
java·linux·c语言·jvm·c++