@@ -0,0 +1,1769 @@
+package leetcode.map;%0A%0A/**%0A * Created by Joshua on 6/19/17.%0A */%0A// Java program to fnd number of islands using Disjoint%0A// Set data structure.%0Aimport java.io.IOException;%0A%0Apublic class NumberofIslands1%0A%7B%0A    public static void main(String%5B%5D args)throws IOException%0A    %7B%0A        int%5B%5D%5B%5D a = new int%5B%5D%5B%5D %7B%7B1, 1, 0, 0, 0%7D,%0A                %7B0, 1, 0, 0, 1%7D,%0A                %7B1, 0, 0, 1, 1%7D,%0A                %7B0, 0, 0, 0, 0%7D,%0A                %7B1, 0, 1, 0, 1%7D%0A        %7D;%0A        System.out.println(%22Number of Islands is: %22 +%0A                countIslands(a));%0A        for (int i=0; i%3Ca.length ;i++) %7B%0A            for (int j=0; j%3Ca%5B0%5D.length; j++) %7B%0A                System.out.print(a%5Bi%5D%5Bj%5D + %22 %22);%0A            %7D%0A            System.out.println();%0A        %7D%0A    %7D%0A%0A    private static int countIslands(int%5B%5D%5B%5D a) %7B%0A        int cursor = 0;%0A        for (int i=0; i%3Ca.length; i++) %7B%0A            for (int j=0; j%3Ca%5B0%5D.length; j++) %7B%0A                int cell = a%5Bi%5D%5Bj%5D;%0A%0A                if (cell == 1) %7B%0A                    int count = getCountFromTopLeft(a, i, j);%0A                    if(count == 0) %7B%0A                        a%5Bi%5D%5Bj%5D = ++cursor;%0A                    %7D%0A                    else %7B%0A                        a%5Bi%5D%5Bj%5D = count;%0A                    %7D%0A                %7D%0A%0A            %7D%0A        %7D%0A        return cursor;%0A    %7D%0A%0A    private static int getCountFromTopLeft(int%5B%5D%5B%5D a, int i, int j) %7B%0A%0A        if (i-1 %3E=0 && a%5Bi-1%5D%5Bj%5D %3E 0) %7B%0A            return a%5Bi-1%5D%5Bj%5D;%0A        %7D%0A        if (j-1%3E=0 && a%5Bi%5D%5Bj-1%5D %3E 0) %7B%0A            return a%5Bi%5D%5Bj-1%5D;%0A        %7D%0A        if (i-1 %3E=0 && j-1%3E=0 && a%5Bi-1%5D%5Bj-1%5D %3E 0) %7B%0A            return a%5Bi-1%5D%5Bj-1%5D;%0A        %7D%0A        if (i-1 %3E=0 && j+1 %3C a%5B0%5D.length && a%5Bi-1%5D%5Bj+1%5D %3E 0) %7B%0A            return a%5Bi-1%5D%5Bj+1%5D;%0A        %7D%0A        return 0;%0A    %7D%0A%0A%7D

num of islands