package leetcode;

/**
 * https://leetcode.com/problems/special-positions-in-a-binary-matrix/
 */
public class Problem1582 {
    public int numSpecial(int[][] mat) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1582 prob = new Problem1582();
        System.out.println(prob.numSpecial(new int[][]{
            {1, 0, 0},
            {0, 0, 1},
            {1, 0, 0}
        })); // 1
        System.out.println(prob.numSpecial(new int[][]{
            {1, 0, 0},
            {0, 1, 0},
            {0, 0, 1}
        })); // 3
        System.out.println(prob.numSpecial(new int[][]{
            {0, 0, 0, 1},
            {1, 0, 0, 0},
            {0, 1, 1, 0},
            {0, 0, 0, 0}
        })); // 2
        System.out.println(prob.numSpecial(new int[][]{
            {0, 0, 0, 0, 0},
            {1, 0, 0, 0, 0},
            {0, 1, 0, 0, 0},
            {0, 0, 1, 0, 0},
            {0, 0, 0, 1, 1}
        })); // 3
    }
}

@@ -171,233 +171,690 @@
     
-// TODO%0A        return 0
+int answer = 0;%0A        int maxRow = mat.length
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1582 prob = new Problem1582();%0A        System.out.println(prob.numSpecial(new in
+int maxCol = maxRow %3E 0 ? mat%5B0%5D.length : 0;%0A        boolean%5B%5D%5B%5D processed = new boolean%5BmaxRow%5D%5BmaxCol%5D;%0A        for (int row = 0; row %3C maxRow; row++) %7B%0A            for (int col = 0; col %3C maxCol; col++) %7B%0A                if (mat%5Brow%5D%5Bcol%5D == 1 && !processed%5Brow%5D%5Bcol%5D) %7B%0A                    processed%5Brow%5D%5Bcol%5D = true;%0A                    boolean duplicate = false;%0A                    // up%0A                    for (int r = row - 1; r %3E= 0; r--) %7B%0A                        if (ma
 t%5B
+r
 %5D%5B
-%5D%7B%0A            %7B1, 0, 0%7D,%0A            %7B0, 0, 1%7D,
+col%5D == 1) %7B%0A                            processed%5Br%5D%5Bcol%5D = true;%0A                            duplicate = true;%0A                        %7D
 %0A   
@@ -862,24 +862,24 @@
         
-%7B1, 0, 0
+        
 %7D%0A      
@@ -884,214 +884,421 @@
     
-%7D)); // 1%0A        System.out.println(prob.numSpecial(new int%5B%5D%5B%5D%7B%0A            %7B1, 0, 0%7D,%0A            %7B0, 1, 0%7D,%0A            %7B0, 0, 1%7D%0A        %7D)); // 3%0A        System.out.println(prob.numSpecial(new in
+            // right%0A                    for (int c = col + 1; c %3C maxCol; c++) %7B%0A                        if (mat%5Brow%5D%5Bc%5D == 1) %7B%0A                            processed%5Brow%5D%5Bc%5D = true;%0A                            duplicate = true;%0A                        %7D%0A                    %7D%0A                    // down%0A                    for (int r = row + 1; r %3C maxRow; r++) %7B%0A                        if (ma
 t%5B
+r
 %5D%5B
-%5D
+col%5D == 1) 
 %7B%0A  
@@ -1311,334 +1311,583 @@
     
-%7B0, 0, 0, 1%7D,%0A            %7B1, 0, 0, 0%7D,%0A            %7B0, 1, 1, 0%7D,%0A            %7B0, 0, 0, 0%7D%0A        %7D)); // 2%0A        System.out.println(prob.numSpecial(new int%5B%5D%5B%5D%7B%0A            %7B0, 0, 0, 0, 0%7D,%0A            %7B1, 0, 0, 0, 0%7D,%0A            %7B0, 1, 0, 0, 0%7D,%0A            %7B0, 0, 1, 0, 0%7D,%0A            %7B0, 0, 0, 1, 1%7D%0A        %7D)); // 3
+                processed%5Br%5D%5Bcol%5D = true;%0A                            duplicate = true;%0A                        %7D%0A                    %7D%0A                    // left%0A                    for (int c = col - 1; c %3E= 0; c--) %7B%0A                        if (mat%5Brow%5D%5Bc%5D == 1) %7B%0A                            processed%5Brow%5D%5Bc%5D = true;%0A                            duplicate = true;%0A                        %7D%0A                    %7D%0A                    if (!duplicate) %7B%0A                        answer++;%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1582