Leetcode73矩阵置零

编程入门 行业动态 更新时间:2024-10-17 23:26:37

Leetcode73<a href=https://www.elefans.com/category/jswz/34/1769510.html style=矩阵置零"/>

Leetcode73矩阵置零

1110-3

代码:

和题解思路差不多

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;}}}
}

更多推荐

Leetcode73矩阵置零

本文发布于:2023-11-15 18:11:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603960.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:矩阵

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!