@@ -0,0 +1,1067 @@
+package com.pengyifan.leetcode;%0A%0A/**%0A * Given a m x n matrix, if an element is 0, set its entire row and column to%0A * 0. Do it in place.%0A * %3Cp%3E%0A * click to show follow up. Follow up:%0A * %3Cp%3E%0A * Did you use extra space?%0A * %3Cp%3E%0A * A straight forward solution using O(mn) space is probably a bad idea.%0A * %3Cp%3E%0A * A simple improvement uses O(m + n) space, but still not the best solution.%0A * %3Cp%3E%0A * Could you devise a constant space solution?%0A */%0Apublic class SetMatrixZeroes %7B%0A%0A  public void setZeroes(int%5B%5D%5B%5D matrix) %7B%0A    if (matrix == null %7C%7C matrix.length == 0) %7B%0A      return;%0A    %7D%0A%0A    int row%5B%5D = new int%5Bmatrix.length%5D;%0A    int col%5B%5D = new int%5Bmatrix%5B0%5D.length%5D;%0A%0A    for (int i = 0; i %3C matrix.length; i++) %7B%0A      for (int j = 0; j %3C matrix%5Bi%5D.length; j++) %7B%0A        if (matrix%5Bi%5D%5Bj%5D == 0) %7B%0A          row%5Bi%5D = -1;%0A          col%5Bj%5D = -1;%0A        %7D%0A      %7D%0A    %7D%0A    for (int i = 0; i %3C matrix.length; i++) %7B%0A      for (int j = 0; j %3C matrix%5Bi%5D.length; j++) %7B%0A        if (row%5Bi%5D == -1 %7C%7C col%5Bj%5D == -1) %7B%0A          matrix%5Bi%5D%5Bj%5D = 0;%0A        %7D%0A      %7D%0A    %7D%0A  %7D%0A%7D%0A

set matrix zeroes