package leetcode;

/**
 * https://leetcode.com/problems/number-of-islands/
 */
public class Problem200 {
    public int numIslands(char[][] grid) {
        return 0;
    }

    public static void main(String[] args) {
        Problem200 prob = new Problem200();

    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashSet;%0Aimport java.util.Set;%0A%0A
 /**%0A * h
@@ -202,114 +202,1437 @@
     
-return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem200 prob = new Problem200();%0A
+Set%3CString%3E zeroes = new HashSet%3C%3E();%0A        Set%3CString%3E ones = new HashSet%3C%3E();%0A        for (int row = 0; row %3C grid.length; row++) %7B%0A            for (int col = 0; col %3C grid%5Brow%5D.length; col++) %7B%0A                if (grid%5Brow%5D%5Bcol%5D == '1') %7B%0A                    ones.add(buildKey(row, col));%0A                %7D else %7B%0A                    zeroes.add(buildKey(row, col));%0A                %7D%0A            %7D%0A        %7D%0A        int result = 0;%0A        while (!ones.isEmpty()) %7B%0A            String%5B%5D str = ones.iterator().next().split(%22%5C%5C%7C%22);%0A            int row = Integer.parseInt(str%5B0%5D);%0A            int col = Integer.parseInt(str%5B1%5D);%0A            numIslands(grid, row, col, zeroes, ones);%0A            result++;%0A        %7D%0A        return result;%0A    %7D%0A%0A    private void numIslands(char%5B%5D%5B%5D grid, int row, int col, Set%3CString%3E zeroes, Set%3CString%3E ones) %7B%0A        String key = buildKey(row, col);%0A        if (!zeroes.contains(key) && !ones.contains(key)) %7B%0A            return;%0A        %7D%0A        if (grid%5Brow%5D%5Bcol%5D == '0') %7B%0A            zeroes.remove(key);%0A            return;%0A        %7D%0A        ones.remove(key);%0A        numIslands(grid, row-1, col, zeroes, ones); // up%0A        numIslands(grid, row+1, col, zeroes, ones); // down%0A        numIslands(grid, row, col-1, zeroes, ones); // left%0A        numIslands(grid, row, col+1, zeroes, ones); // right%0A    %7D%0A%0A    private String buildKey(int row, int col) %7B%0A        return row + %22%7C%22 + col;
 %0A   

Solve problem 200