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

题目:

题解:

cpp 复制代码
class Solution {
public:
    void setZeroes(vector<vector<int>>& matrix) {
        int m = matrix.size();
        int n = matrix[0].size();
        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;
            }
        }
    }
};
相关推荐
To_OC3 小时前
LC 51 N 皇后:我以为难的是回溯,结果栽在了对角线下标
javascript·算法·leetcode
2401_841495644 小时前
【操作系统】进程同步与互斥实验报告
c++·算法·操作系统·进程·并发·同步·互斥
fqbqrr4 小时前
2607C++,soui与安卓
c++·soui
fqbqrr7 小时前
2607C++,使用微软detours勾挂工具
c++
蓝悦无人机10 小时前
C++基础 — 函数总结
开发语言·c++
我不是懒洋洋12 小时前
从零实现一个分布式监控:Prometheus的核心设计
c++
An_s12 小时前
c++对接pdfium(一)win系统篇
开发语言·c++
众少成多积小致巨12 小时前
C++ 规范参考(上)
c++
闪电悠米15 小时前
力扣hot100-73.矩阵置零-标记数组详解
算法·leetcode·矩阵
一拳一个呆瓜16 小时前
【STL】iostream 编程:使用提取运算符
c++·stl