class Solution { public void setZeroes(int[][] matrix) { Set<Integer> row_zero = new HashSet<>(); Set<Integer> col_zero = new HashSet<>();
int row = matrix.length; int col = matrix[0].length; for(int i = 0; i < row; i ++){ for(int j = 0; j < col; j ++){ if(matrix[i][j] == 0){ row_zero.add(i); col_zero.add(j); } } }
for(int i = 0; i < row; i ++){ for(int j = 0; j < col; j ++){ if(row_zero.contains(i) || col_zero.contains(j)) matrix[i][j] = 0; } } } }
标签:matrix,int,矩阵,力扣,++,zero,col,row From: https://www.cnblogs.com/laidoulaile/p/16874261.html