@@ -0,0 +1,1310 @@
+// Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.%0A%0A// click to show follow up.%0A%0A// Follow up:%0A// Did you use extra space?%0A// A straight forward solution using O(mn) space is probably a bad idea.%0A// A simple improvement uses O(m + n) space, but still not the best solution.%0A// Could you devise a constant space solution?%0A%0Apublic class Solution %7B%0A    public void setZeroes(int%5B%5D%5B%5D matrix) %7B%0A%09%09// O(mn) solution, use one additional matrix;%0A%0A%09%09// O(m + n) solution, use two arrays to store the 0s positions.%0A%09%09int row = matrix.length;%0A%0A%09%09if(row == 0) return;%0A%0A%09%09int col = matrix%5B0%5D.length;%0A%0A%09%09boolean%5B%5D rowIndex = new boolean%5Brow%5D;%0A%09%09boolean%5B%5D colIndex = new boolean%5Bcol%5D;%0A%0A%09%09for(int i = 0; i %3C row; i++)%7B%0A%09%09%09for(int j= 0; j %3C col; j++)%7B%0A%09%09%09%09// if(rowIndex%5Bi%5D %7C%7C colIndex%5Bj%5D)%7B%0A%09%09%09%09// %09continue;%0A%09%09%09%09// %7D%0A%0A%09%09%09%09if(matrix%5Bi%5D%5Bj%5D == 0)%7B%0A%09%09%09%09%09rowIndex%5Bi%5D = true;%0A%09%09%09%09%09colIndex%5Bj%5D = true;%0A%09%09%09%09%09// continue;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09for(int i = 0; i %3C rowIndex.length; i++)%7B%0A%09%09%09if(rowIndex%5Bi%5D)%7B%0A%09%09%09%09// clear a certain row in input matrix.%0A%09%09%09%09for(int j = 0; j %3C col; j++)%7B%0A%09%09%09%09%09matrix%5Bi%5D%5Bj%5D = 0;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09for(int j = 0; j %3C colIndex.length; j++)%7B%0A%09%09%09if(colIndex%5Bj%5D)%7B%0A%09%09%09%09// same as the above.%0A%09%09%09%09for(int i = 0; i %3C row; i++)%7B%0A%09%09%09%09%09matrix%5Bi%5D%5Bj%5D = 0;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%0A    %7D%0A%7D

add set matrix zeros solution;