代码实现
class Solution {public void setZeroes(int[][] matrix) {boolean[] x=new boolean[matrix.length];boolean[] y=new boolean[matrix[0].length];for(int i=0;i<matrix.length;i++){for(int j=0;j<matrix[0].length;j++){if(matrix[i][j]==0){x[i]=true;y[j]=true; }}}for(int i=0;i<matrix.length;i++){for(int j=0;j<matrix[0].length;j++){if(x[i]||y[j]){matrix[i][j]=0; }}} }
}
注意事项
不能边遍历边置0,会影响数组中的其他元素