Set Matrix Zeroes
和感染列岛那道题有点共鸣 http://www.cnblogs.com/jiajiaxingxing/p/4405731.html
这道题就是细节比较多吧
code ganker 的总结http://blog.csdn.net/linhuanmars/article/details/39248597
public class Solution { public void setZeroes(int[][] matrix) { int col = matrix[0].length; int row = matrix.length; if(col*row==0) return; boolean fr0 = false, fc0= false; for(int i=0; i<col;i++){ if(matrix[0][i]==0){ fr0 = true; break; } } for(int j=0; j< row; j++){ if(matrix[j][0]==0){ fc0=true; break; } } for(int i=1;i<row;i++){ for(int j=1; j<col;j++){ if(matrix[i][j]==0){ matrix[0][j] = 0; matrix[i][0] = 0; } } } for(int i=1;i<row;i++){ for(int j=1; j<col;j++){ if(matrix[0][j] == 0||matrix[i][0] == 0) matrix[i][j]=0; } } if(fr0){ for(int i=0;i<col;i++){ matrix[0][i]=0; } } if(fc0){ for(int j=0; j< row; j++){ matrix[j][0]=0; } } } }