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[][] visited = new boolean[maxRow][maxCol];
        for (int row = 0; row < maxRow; row++) {
            for (int col = 0; col < maxCol; col++) {
                if (visited[row][col]) {
                    continue;
                }
                // TODO
            }
        }
        return 0;
    }

    private static void shortest(int[][] a, int maxRow, int maxCol, int row, int col) {
        // top
        if (row - 1 >= 0) {

        }
        // right
        if (col + 1 < maxCol) {

        }
        // bottom
        if (row + 1 < maxRow) {

        }
        // left
        if (col - 1 >= 0) {

        }
    }

    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
    }
}

@@ -244,16 +244,77 @@
  visited
+1 = new boolean%5BmaxRow%5D%5BmaxCol%5D;%0A        boolean%5B%5D%5B%5D visited2
  = new b
@@ -443,97 +443,8 @@
 ) %7B%0A
-                if (visited%5Brow%5D%5Bcol%5D) %7B%0A                    continue;%0A                %7D%0A
     
@@ -536,24 +536,24 @@
 ic void 
-shortest
+traverse
 (int%5B%5D%5B%5D
@@ -596,19 +596,17 @@
  int col
-) %7B
+,
 %0A       
@@ -610,52 +610,132 @@
     
-// top%0A        if (row - 1 %3E= 0
+                         boolean%5B%5D%5B%5D visited) %7B%0A        if (row %3C 0 %7C%7C row %3E= maxRow %7C%7C col %3C 0 %7C%7C col %3E= maxCol
 ) %7B%0A
-%0A
         
 %7D%0A  
@@ -734,87 +734,161 @@
     
-%7D%0A
     
-    // right%0A        if (col + 1 %3C maxCol) %7B%0A%0A        %7D%0A        // bottom
+return;%0A        %7D%0A        if (visited%5Brow%5D%5Bcol%5D %7C%7C a%5Brow%5D%5Bcol%5D == 0) %7B%0A            return;%0A        %7D%0A        visited%5Brow%5D%5Bcol%5D = true;%0A        // top
 %0A   
@@ -896,42 +896,136 @@
     
-if (
+traverse(a, maxRow, maxCol, 
 row 
-+ 1 %3C maxRow) %7B%0A%0A        %7D
+- 1, col, visited);%0A        // right%0A        traverse(a, maxRow, maxCol, row, col + 1, visited);
 %0A   
@@ -1036,12 +1036,14 @@
  // 
-left
+bottom
 %0A   
@@ -1051,38 +1051,135 @@
     
-if (col - 1 %3E= 0) %7B%0A%0A        %7D
+traverse(a, maxRow, maxCol, row + 1, col, visited);%0A        // left%0A        traverse(a, maxRow, maxCol, row, col - 1, visited);
 %0A   

Update problem 934