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();
    }
};
相关推荐
Ronin-Lotus1 分钟前
程序代码篇---C/C++中的变量存储位置
c语言·c++···静态区·文字常量区·变量存储位置
且听风吟ayan17 分钟前
leetcode day20 滑动窗口209+904
算法·leetcode·c#
m0_6759882317 分钟前
Leetcode350:两个数组的交集 II
算法·leetcode·数组·哈希表·python3
_Itachi__18 分钟前
LeetCode 热题 100 160. 相交链表
算法·leetcode·链表
m0_6759882321 分钟前
Leetcode1206:设计跳表
算法·leetcode·跳表·python3
冠位观测者22 分钟前
【Leetcode 每日一题 - 扩展】1512. 好数对的数目
数据结构·算法·leetcode
Joyner201822 分钟前
python-leetcode-路径总和 III
算法·leetcode·职场和发展
南宫生23 分钟前
力扣每日一题【算法学习day.133】
java·学习·算法·leetcode
_Itachi__24 分钟前
LeetCode 热题 100 560. 和为 K 的子数组
数据结构·算法·leetcode
夏末秋也凉24 分钟前
力扣-贪心-55 跳跃游戏
算法·leetcode·游戏