package leetcode;

/**
 * https://leetcode.com/problems/shortest-bridge/
 */
public class Problem934 {
    public int shortestBridge(int[][] A) {
        int maxRow = A.length;
        int maxCol = maxRow > 0 ? A[0][0] : 0;
        boolean[][] visited1 = new boolean[maxRow][maxCol];
        boolean[][] visited2 = new boolean[maxRow][maxCol];
        for (int row = 0; row < maxRow; row++) {
            for (int col = 0; col < maxCol; col++) {
                // TODO
            }
        }
        return 0;
    }

    private static void traverse(int[][] a, int maxRow, int maxCol, int row, int col,
                                 boolean[][] visited) {
        if (row < 0 || row >= maxRow || col < 0 || col >= maxCol) {
            return;
        }
        if (visited[row][col] || a[row][col] == 0) {
            return;
        }
        visited[row][col] = true;
        // top
        traverse(a, maxRow, maxCol, row - 1, col, visited);
        // right
        traverse(a, maxRow, maxCol, row, col + 1, visited);
        // bottom
        traverse(a, maxRow, maxCol, row + 1, col, visited);
        // left
        traverse(a, maxRow, maxCol, row, col - 1, visited);
    }

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

@@ -459,15 +459,333 @@
     
-// TODO
+if (A%5Brow%5D%5Bcol%5D == 1) %7B%0A                    if (!visited1%5Brow%5D%5Bcol%5D) %7B%0A                        traverse(A, maxRow, maxCol, row, col, visited1);%0A                    %7D%0A                    if (!visited1%5Brow%5D%5Bcol%5D) %7B%0A                        traverse(A, maxRow, maxCol, row, col, visited2);%0A                    %7D%0A                %7D
 %0A   
@@ -1589,16 +1589,18 @@
 m934();%0A
+//
         
@@ -1643,32 +1643,34 @@
 ge(new int%5B%5D%5B%5D%7B%0A
+//
             %7B0, 
@@ -1669,24 +1669,26 @@
     %7B0, 1%7D,%0A
+//
             
@@ -1690,24 +1690,26 @@
      %7B1, 0%7D%0A
+//
         %7D));
@@ -1860,16 +1860,18 @@
 ); // 2%0A
+//
         
@@ -1914,32 +1914,34 @@
 ge(new int%5B%5D%5B%5D%7B%0A
+//
             %7B0, 
@@ -1939,32 +1939,34 @@
      %7B0, 1, 1%7D,%0A
+//
             %7B0, 
@@ -1964,32 +1964,34 @@
      %7B0, 0, 0%7D,%0A
+//
             %7B1, 
@@ -1996,16 +1996,18 @@
 , 1, 0%7D%0A
+//
         
@@ -2008,32 +2008,34 @@
       %7D)); // 1%0A
+//
         System.o
@@ -2070,32 +2070,34 @@
 ge(new int%5B%5D%5B%5D%7B%0A
+//
             %7B1, 
@@ -2105,24 +2105,26 @@
 , 1, 1, 1%7D,%0A
+//
             
@@ -2132,32 +2132,34 @@
 1, 0, 0, 0, 1%7D,%0A
+//
             %7B1, 
@@ -2163,32 +2163,34 @@
 1, 0, 1, 0, 1%7D,%0A
+//
             %7B1, 
@@ -2202,16 +2202,18 @@
  0, 1%7D,%0A
+//
         
@@ -2228,24 +2228,26 @@
 1, 1, 1, 1%7D%0A
+//
         %7D));

Update problem 934