class Solution {//1.用矩阵的第一行和第一列来标记该行或该列是否应该为0,但是这样的话忽视了第一行或第一列为0的情况//2.用标记row0和column0来标记第一行或第一列是否该为0public void setZeroes(int[][] matrix) {int n = matrix.length;int m = matrix[0].length;boolean row0 = false;boolean column0 = false;for(int i = 0; i < n; i++){if(matrix[i][0] == 0){column0 = true;}}for(int j = 0; j < m; j++){if(matrix[0][j] == 0){row0 = true;}}for(int i = 1; i < n; i++){for(int j = 1; j < m; j++){if(matrix[i][j] == 0){matrix[0][j] = 0;matrix[i][0] = 0;}}}for(int i = 1; i < n; i++){for(int j = 1; j < m; j++){if(matrix[i][0] == 0 || matrix[0][j] == 0) matrix[i][j] = 0;}}if(row0){for(int i = 0; i < m; i++) matrix[0][i] = 0;}if(column0){for(int i = 0; i < n; i++) matrix[i][0] = 0;}}
}