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
        }
    }
}
相关推荐
Dream it possible!1 小时前
LeetCode 面试经典 150_二叉树_二叉树中的最大路径和(77_124_C++_困难)(DFS)
c++·leetcode·面试·二叉树
做怪小疯子6 小时前
LeetCode 热题 100——子串——和为 K 的子数组
算法·leetcode·职场和发展
希望有朝一日能如愿以偿11 小时前
力扣每日一题:仅含1的子串数
算法·leetcode·职场和发展
q***710812 小时前
【Golang】——Gin 框架中的表单处理与数据绑定
microsoft·golang·gin
苏小瀚12 小时前
算法---FloodFill算法和记忆化搜索算法
数据结构·算法·leetcode
少许极端15 小时前
算法奇妙屋(十二)-优先级队列(堆)
数据结构·算法·leetcode·优先级队列··图解算法
Kuo-Teng17 小时前
LeetCode 118: Pascal‘s Triangle
java·算法·leetcode·职场和发展·动态规划
q***728717 小时前
Golang 构建学习
开发语言·学习·golang
野蛮人6号18 小时前
力扣热题100道之207课程表
算法·leetcode·职场和发展
学学学无无止境18 小时前
力扣-买卖股票的最佳时机
leetcode