package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/set-matrix-zeroes/
 */
public class Problem73 {
    public void setZeroes(int[][] matrix) {
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[i].length; j++) {
                if (matrix[i][j] == 0) {
                    setRowZeroes(matrix, i);
                    setColZeroes(matrix, j);
                }
            }
        }
    }
    
    private void setRowZeroes(int[][] matrix, int row) {
        for (int i = 0; i < matrix[row].length; i++) {
            matrix[row][i] = 0;
        }
    }
    
    private void setColZeroes(int[][] matrix, int col) {
        for (int i = 0; i < matrix.length; i++) {
            matrix[i][col] = 0;
        }
    }
    
    public static void main(String[] args) {
        Problem73 prob = new Problem73();
        int[][] matrix = new int[][] {
            new int[]{1, 0, 1, 1},
            new int[]{0, 1, 1, 1},
            new int[]{1, 1, 1, 1}
        };
        prob.setZeroes(matrix);
        for (int i = 0; i < matrix.length; i++) {
            System.out.println(Arrays.toString(matrix[i]));
        }
    }
}

@@ -34,17 +34,68 @@
 il.Array
-s
+List;%0Aimport java.util.Arrays;%0Aimport java.util.List
 ;%0A%0A/**%0A 
@@ -214,24 +214,71 @@
 %5D matrix) %7B%0A
+        List%3CZero%3E zeroes = new ArrayList%3C%3E();%0A
         for 
@@ -437,41 +437,113 @@
     
-setRowZeroes(matrix, i);%0A        
+zeroes.add(new Zero(i, j));%0A                %7D%0A            %7D%0A        %7D%0A        for (Zero zero : zeroes) %7B%0A
     
@@ -549,27 +549,27 @@
          set
-Col
+Row
 Zeroes(matri
@@ -571,17 +571,24 @@
 matrix, 
-j
+zero.row
 );%0A     
@@ -582,32 +582,68 @@
 o.row);%0A        
+    setColZeroes(matrix, zero.col);%0A
         %7D%0A      
@@ -644,39 +644,82 @@
     
-    
+%7D%0A
     
-%7D
 %0A    
-    %7D%0A    %7D
+private static class Zero %7B%0A        private final int row;
 %0A    
-%0A
     
@@ -730,49 +730,68 @@
 ate 
-void setRow
+final int col;%0A        %0A        public 
 Zero
-es
 (int
-%5B%5D%5B%5D matrix
+ row
 , int 
-row
+col
 ) %7B%0A
@@ -802,85 +802,54 @@
     
-for (int i = 0; i %3C matrix%5Brow%5D.length; i++) %7B%0A            matrix%5Brow%5D%5Bi%5D = 0
+    this.row = row;%0A            this.col = col
 ;%0A  
@@ -883,27 +883,27 @@
 ate void set
-Col
+Row
 Zeroes(int%5B%5D
@@ -913,27 +913,27 @@
 matrix, int 
-col
+row
 ) %7B%0A        
@@ -950,32 +950,37 @@
  = 0; i %3C matrix
+%5Brow%5D
 .length; i++) %7B%0A
@@ -1002,14 +1002,14 @@
 rix%5B
-i%5D%5Bcol
+row%5D%5Bi
 %5D = 
@@ -1041,275 +1041,59 @@
    p
-ublic static void main(String%5B%5D args) %7B%0A        Problem73 prob = new Problem73();%0A        int%5B%5D%5B%5D matrix = new int%5B%5D%5B%5D %7B%0A            new int%5B%5D%7B1, 0, 1, 1%7D,%0A            new int%5B%5D%7B0, 1, 1, 1%7D,%0A            new int%5B%5D%7B1, 1, 1, 1%7D%0A        %7D;%0A        prob.setZeroes(matrix);
+rivate void setColZeroes(int%5B%5D%5B%5D matrix, int col) %7B
 %0A   
@@ -1155,54 +1155,26 @@
     
-System.out.println(Arrays.toString(matrix%5Bi%5D))
+matrix%5Bi%5D%5Bcol%5D = 0
 ;%0A  

Solve problem 73