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;
            }
        }
    }
}
相关推荐
历程里程碑43 分钟前
LeetCode热题11:盛水容器双指针妙解
c语言·数据结构·c++·经验分享·算法·leetcode·职场和发展
_OP_CHEN1 小时前
【C++数据结构进阶】从B + 树 / B * 树到数据库索引:B树的进化之路与 MySQL 实战解析
数据结构·数据库·b树·mysql·innodb·b+树·mylsam
wadesir8 小时前
Rust中的条件变量详解(使用Condvar的wait方法实现线程同步)
开发语言·算法·rust
yugi9878388 小时前
基于MATLAB实现协同过滤电影推荐系统
算法·matlab
TimberWill8 小时前
哈希-02-最长连续序列
算法·leetcode·排序算法
Morwit8 小时前
【力扣hot100】64. 最小路径和
c++·算法·leetcode
leoufung8 小时前
LeetCode 373. Find K Pairs with Smallest Sums:从暴力到堆优化的完整思路与踩坑
java·算法·leetcode
wifi chicken9 小时前
数组遍历求值,行遍历和列遍历谁更快
c语言·数据结构·算法
qingyun9899 小时前
深度优先遍历:JavaScript递归查找树形数据结构中的节点标签
前端·javascript·数据结构
胡楚昊9 小时前
NSSCTF动调题包通关
开发语言·javascript·算法