public static void setZeroes(int[][] matrix) {
if(matrix == null || matrix.length == 0 ) {
return ;
}
int[] path = new int[matrix.length*matrix[0].length];
int count = 0;
for(int i = 0; i < matrix.length; i++) {
for(int j = 0; j < matrix[0].length; j++) {
if(matrix[i][j] == 0) {
path[count++] = i * matrix[0].length+j;
}
}
}
for(int i = 0; i < count; i++) {
int rol = path[i] / matrix[0].length;
int col = path[i] % matrix[0].length;
int j = 0;
while(j < matrix[0].length) {
matrix[rol][j++] = 0;
}
j = 0;
while(j < matrix.length) {
matrix[j++][col] = 0;
}
}
}
73. Set Matrix Zeroes
最新推荐文章于 2025-05-04 15:02:14 发布