73. Set Matrix Zeroes

来源:互联网 发布:js qq在线客服插件 编辑:程序博客网 时间:2024/06/07 09:54
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;             }         }    }
0 0
原创粉丝点击