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
        }
    }
}
相关推荐
北顾笙9803 分钟前
day11-数据结构力扣
数据结构·算法·leetcode
weixin_4492900135 分钟前
Python vs Go:优缺点对比
网络·python·golang
会编程的土豆37 分钟前
【leetcode hot 100】二叉树二叉树
数据结构·算法·leetcode
XiYang-DING40 分钟前
【LeetCode】203. 移除链表元素(Remove Linked List Elements)
算法·leetcode·链表
圣保罗的大教堂44 分钟前
leetcode 2751. 机器人碰撞 困难
leetcode
xsyaaaan1 小时前
leetcode-hot100-图论:200岛屿数量-994腐烂的橘子-207课程表-208实现前缀树
leetcode·图论
We་ct1 小时前
LeetCode 67. 二进制求和:详细题解+代码拆解
前端·数据结构·算法·leetcode·typescript
Morwit1 小时前
【力扣hot100】 70. 爬楼梯
c++·算法·leetcode·职场和发展
Tisfy1 小时前
LeetCode 3474.字典序最小的生成字符串:暴力填充
算法·leetcode·字符串·题解
亿牛云爬虫专家1 小时前
Go Colly框架高阶技巧:如何在中间件中无缝切换代理IP
tcp/ip·中间件·golang·爬虫代理·代理ip·snippet·go colly