矩阵置零"/>
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矩阵置零
发布评论