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

题目:

题解:

cpp 复制代码
int uniquePathsWithObstacles(int** obstacleGrid, int obstacleGridSize,
                             int* obstacleGridColSize) {
    int n = obstacleGridSize, m = obstacleGridColSize[0];
    int f[m];
    memset(f, 0, sizeof(f));
    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[m - 1];
}
相关推荐
Tisfy6 小时前
LeetCode 2553.分割数组中数字的数位:模拟(maybe+翻转)——java也O(1)
java·数学·算法·leetcode·题解·模拟·取模
Controller-Inversion6 小时前
42. 接雨水
数据结构·算法·leetcode
Controller-Inversion6 小时前
33. 搜索旋转排序数组
数据结构·算法·leetcode
驼同学.6 小时前
【求职季】LeetCode Hot 100 渐进式扫盲手册(Python版)
python·算法·leetcode
宵时待雨7 小时前
优选算法专题6:模拟
数据结构·c++·算法·leetcode·职场和发展
Liangwei Lin7 小时前
LeetCode 35. 搜索插入位置
数据结构·算法·leetcode
邪修king7 小时前
C++ 继承超全详解:核心语法、作用域、默认函数、菱形继承与避坑指南
c语言·c++
djarmy7 小时前
C 标准库 `<stdio.h>` 完整函数清单(官方标准 + 常用全部函数)
c语言·c++·算法
洛水水8 小时前
【力扣100题】22. 矩阵置零
算法·leetcode·矩阵
Liangwei Lin8 小时前
LeetCode 78. 子集
数据结构·算法·leetcode