C语言 | Leetcode C语言题解之第73题矩阵置零

题目:

题解:

cpp 复制代码
void setZeroes(int** matrix, int matrixSize, int* matrixColSize) {
    int m = matrixSize;
    int n = matrixColSize[0];
    int flag_col0 = false;
    for (int i = 0; i < m; i++) {
        if (!matrix[i][0]) {
            flag_col0 = true;
        }
        for (int j = 1; j < n; j++) {
            if (!matrix[i][j]) {
                matrix[i][0] = matrix[0][j] = 0;
            }
        }
    }
    for (int i = m - 1; i >= 0; i--) {
        for (int j = 1; j < n; j++) {
            if (!matrix[i][0] || !matrix[0][j]) {
                matrix[i][j] = 0;
            }
        }
        if (flag_col0) {
            matrix[i][0] = 0;
        }
    }
}
相关推荐
pursuit_csdn3 小时前
LeetCode 1022. Sum of Root To Leaf Binary Numbers
算法·leetcode·深度优先
踩坑记录5 小时前
leetcode hot100 35. 搜索插入位置 medium 二分查找
leetcode
m0_531237176 小时前
C语言-指针终阶
c语言·开发语言
散峰而望6 小时前
C++ 启程:从历史到实战,揭开命名空间的神秘面纱
c语言·开发语言·数据结构·c++·算法·github·visual studio
水饺编程7 小时前
第4章,[标签 Win32] :TextOut 测试案例3代码改编
c语言·c++·windows·visual studio
-海绵东东-7 小时前
哈希表······················
算法·leetcode·散列表
菜鸡儿齐8 小时前
leetcode-全排列
算法·leetcode·深度优先
不想看见4048 小时前
Maximal Square 基本动态规划:二维--力扣101算法题解笔记
算法·leetcode·动态规划
夏乌_Wx8 小时前
LeetCode 160. 相交链表 | 三种解法吃透核心逻辑(哈希表 + 双指针 + 长度对齐)
leetcode·链表·哈希表
Hag_208 小时前
LeetCode Hot100 53.最大子数组和
数据结构·算法·leetcode