classSolution {publicvoidsetZeroes(int[][] matrix) {if(matrix ==null||matrix.length==0|| matrix[0].length==0)return;int m =matrix.length;int n = matrix[0].length;boolean firstRowZero =false;boolean firstColZero =false;//check if first row needs to be changed to zerofor(int j =0; j < n; j++) {if(matrix[0][j] ==0) { firstRowZero =true;break; } }//check if first col needs to be changed to zerofor(int i =0; i < m; i++) {if(matrix[i][0] ==0) { firstColZero =true;break; } }//mark the row col which have zero in first row and colfor(int i =1; i < m ;i++) {for(int j =1; j < n; j++) {if(matrix[i][j] ==0) { matrix[i][0] =0; matrix[0][j] =0; } } }//fill in the zeroesfor(int i =1; i < m ;i++) {for(int j =1; j < n; j++) {if(matrix[i][0] ==0|| matrix[0][j] ==0) matrix[i][j] =0; } }//update first rowif(firstRowZero) {for(int j =0; j < n; j++) matrix[0][j] =0; }//update first colif(firstColZero) {for(int i =0; i < m; i++) matrix[i][0] =0; } }}