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];
}
相关推荐
tkevinjd2 分钟前
反转链表及其应用(力扣2130)
数据结构·leetcode·链表
程序员烧烤1 小时前
【leetcode刷题007】leetcode116、117
算法·leetcode
yanqiaofanhua1 小时前
C语言自学--预处理详解
c语言·开发语言
杨福瑞3 小时前
C语言⽂件操作讲解(总)
c语言·开发语言
Swift社区4 小时前
LeetCode 395 - 至少有 K 个重复字符的最长子串
算法·leetcode·职场和发展
Espresso Macchiato4 小时前
Leetcode 3710. Maximum Partition Factor
leetcode·职场和发展·广度优先遍历·二分法·leetcode hard·leetcode 3710·leetcode双周赛167
巴里巴气5 小时前
第15题 三数之和
数据结构·算法·leetcode
润 下5 小时前
C语言——深入解析C语言指针:从基础到实践从入门到精通(三)
c语言·开发语言·经验分享·笔记·学习·程序人生·其他
润 下6 小时前
C语言——深入解析C语言指针:从基础到实践从入门到精通(二)
c语言·开发语言·经验分享·笔记·学习·程序人生
西阳未落6 小时前
LeetCode——双指针(进阶)
c++·算法·leetcode