技术栈

C++ | Leetcode C++题解之第63题不同路径II

Ddddddd_1582024-05-06 20:42

题目:

题解:

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();
    }
};
上一篇:redis进阶--IDEA环境
下一篇:java反射
相关推荐
文丑颜不良啊
26 分钟前
LeetCode851~875题目解析
java·leetcode
Navigator_Z
41 分钟前
LeetCode //C - 1304. Find N Unique Integers Sum up to Zero
c语言·算法·leetcode
Yyyyyy~
1 小时前
【C++】String
c++
会编程的小孩
10 小时前
C++ qt的安装
c++
?abc!
13 小时前
(数组)581. 最短无序连续子数组
数据结构·算法·leetcode
小成20230320265
15 小时前
C++~07补充
开发语言·c++
hold?fish:palm
15 小时前
40 二叉树的直径
c++·leetcode
解决小子
16 小时前
【虚幻引擎】【C++】【GAS框架】构建角色基类、属性集、数值钳制
c++·笔记·游戏引擎·虚幻·gas·能力系统
guo_wen_qiang
16 小时前
二叉树的层序遍历-使用双端队列Deque
算法·leetcode·1024程序员节
爱读书的小胖
17 小时前
LeetCode 55 跳跃游戏 C 语言解题分析
c语言·数据结构·算法·leetcode·1024程序员节
热门推荐
01国内可直接用、免费额度/永久免费的大模型API清单(含 SiliconFlow、火山、阿里、智谱、百度、Kimi、DeepSeek、DMXAPI 等)02如何新建文件夹? 电脑新建文件夹的4种方法03GitHub 镜像站点04历年考研数学一、数学二、数学三真题试卷及答案PDF05几个好用的ip纯净度检测网站06苹果iPA游戏软件资源下载网站07ai安全工具:CyberStrikeAI安装部署与使用08昇腾910B系列芯片完全指南:四款型号对比、服务器选型与大模型部署实战09蜘蛛磁力 搜索引擎大全,如何使用蜘蛛磁力查找磁力链接10乙二醇水溶液物性参数