Leetcode73矩阵置零

1110-3

代码:

和题解思路差不多

java 复制代码
class Solution {
    public void setZeroes(int[][] matrix) {
        Set<Integer> setr = new HashSet<>();
        Set<Integer> setc = new HashSet<>();
        for(int i=0;i<matrix.length;i++){
            for(int j=0;j<matrix[0].length;j++){
                if(matrix[i][j]==0){
                    setr.add(i);
                    setc.add(j);
                }
            }
        }
        for(int r:setr){
            for(int i=0;i<matrix[0].length;i++){
                matrix[r][i] = 0;
            }
        }
        for(int c:setc){
            for(int i=0;i<matrix.length;i++){
                matrix[i][c] = 0;
            }
        }
    }
}
相关推荐
smj2302_796826521 小时前
解决leetcode第3768题.固定长度子数组中的最小逆序对数目
python·算法·leetcode
cynicme1 小时前
力扣3531——统计被覆盖的建筑
算法·leetcode
core5122 小时前
深度解析DeepSeek-R1中GRPO强化学习算法
人工智能·算法·机器学习·deepseek·grpo
mit6.8242 小时前
计数if|
算法
a伊雪2 小时前
c++ 引用参数
c++·算法
Data_agent3 小时前
1688获得1688店铺列表API,python请求示例
开发语言·python·算法
2301_764441333 小时前
使用python构建的应急物资代储博弈模型
开发语言·python·算法
小熳芋3 小时前
验证二叉搜索树- python-递归&上下界约束
数据结构
hetao17338374 小时前
2025-12-11 hetao1733837的刷题笔记
c++·笔记·算法
Xの哲學4 小时前
Linux电源管理深度剖析
linux·服务器·算法·架构·边缘计算