Golang | Leetcode Golang题解之第73题矩阵置零

题目:

题解:

Go 复制代码
func setZeroes(matrix [][]int) {
    n, m := len(matrix), len(matrix[0])
    col0 := false
    for _, r := range matrix {
        if r[0] == 0 {
            col0 = true
        }
        for j := 1; j < m; j++ {
            if r[j] == 0 {
                r[0] = 0
                matrix[0][j] = 0
            }
        }
    }
    for i := n - 1; i >= 0; i-- {
        for j := 1; j < m; j++ {
            if matrix[i][0] == 0 || matrix[0][j] == 0 {
                matrix[i][j] = 0
            }
        }
        if col0 {
            matrix[i][0] = 0
        }
    }
}
相关推荐
smj2302_796826527 小时前
解决leetcode第3943题递增后的数对数量
数据结构·python·算法·leetcode
姚不倒10 小时前
从零实现一个基于 Ollama + Go + MySQL 的 Text-to-SQL 智能体(M1 实战)
sql·mysql·云原生·golang
医用门10 小时前
医院用门一线品牌
leetcode
he___H11 小时前
leetcode100-普通数组
java·数据结构·算法·leetcode
菜菜的顾清寒15 小时前
力扣HOT100(30)两两交换链表中的节点
算法·leetcode·链表
csdn_aspnet17 小时前
C++ 算法 LeetCode 编号 70 - 爬楼梯
开发语言·c++·算法·leetcode
圣保罗的大教堂17 小时前
leetcode 2770. 达到末尾下标所需的最大跳跃次数 中等
leetcode
wlsh1518 小时前
Go 泛型笔记
golang
姚不倒18 小时前
从「LeetCode LRU 缓存」到「生产级 Go Web 服务」:我如何迈出工程化第一步
leetcode·缓存·云原生·golang
sheeta199818 小时前
LeetCode 每日一题笔记 日期:2026.05.25 题目:1871. 跳跃游戏 VII
笔记·leetcode·游戏