在二维矩阵中出现0的所在行和所在列均置为0
简单标记即可
public class Solution {
public void setZeroes(int[][] matrix) {
boolean visRow[] = new boolean[matrix.length];
boolean visCol[] = new boolean[matrix[0].length];
Arrays.fill(visRow, false);
Arrays.fill(visCol, false);
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){
visRow[i] = true;
visCol[j] = true;
}
}
}
for(int i = 0; i < row; ++i){
if(visRow[i]){
for(int k = 0; k < col; ++k){
matrix[i][k] = 0;
}
}
}
for(int i = 0; i < col; ++i){
if(visCol[i]){
for(int k = 0; k < row; ++k){
matrix[k][i] = 0;
}
}
}
}
}