Given a m x n Matrix, if an element was 0, set its entire row and column to 0. Do it on place.
Public classSolution { Public voidSetzeroes (int[] matrix) { //The topic requires no extra space, so you need to use the space of the matrix itself to assist storage,//The first and first columns of the matrix are borrowed to assist in recording the row or whether the column is 0. Because the first column of the first row itself has changed, and then two variables are used to record whether the first row and the first column are//0. intrlen=matrix.length; intClen=matrix[0].length; intRow=1; intCol=1; for(inti=0;i<rlen;i++){ if(matrix[i][0]==0) {col=0; Break; } } for(inti=0;i<clen;i++){ if(matrix[0][i]==0) {row=0; Break; } } for(inti=1;i<rlen;i++) {//Note: No special considerations are required for rows 1th and 1th, as only the original value can be guaranteed!! for(intj=1;j<clen;j++){ if(matrix[i][j]==0) {matrix[i][0]=0; matrix[0][j]=0; } } } for(inti=1;i<rlen;i++){ for(intj=1;j<clen;j++){ if(matrix[i][0]==0| | Matrix[0][j]==0) Matrix[i][j]=0; } } if(row==0){ for(inti=0;i<clen;i++) {matrix[0][i]=0; } } if(col==0){ for(inti=0;i<rlen;i++) {matrix[i][0]=0; } } }}
[Leedcode 73] Set Matrix Zeroes