package leetcode;

/**
 * https://leetcode.com/problems/battleships-in-a-board/
 */
public class Problem419 {
    public int countBattleships(char[][] board) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem419 prob = new Problem419();
        System.out.println(prob.countBattleships(new char[][]{
            new String("X..X").toCharArray(),
            new String("...X").toCharArray(),
            new String("...X").toCharArray()
        })); // 2
    }
}

@@ -165,347 +165,833 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem419 prob = new Problem419();%0A        System.out.println(prob.countBattleships(new char%5B%5D%5B%5D%7B%0A            new String(%22X..X%22).toCharArray(),%0A            new String(%22...X%22).toCharArray(),%0A            new String(%22...X%22).toCharArray()%0A        %7D)); // 2
+boolean%5B%5D%5B%5D marked = new boolean%5Bboard.length%5D%5Bboard%5B0%5D.length%5D;%0A        int count = 0;%0A        for (int i = 0; i %3C board.length; i++) %7B%0A            for (int j = 0; j %3C board%5Bi%5D.length; j++) %7B%0A                if (board%5Bi%5D%5Bj%5D == 'X' && !marked%5Bi%5D%5Bj%5D) %7B%0A                    marked%5Bi%5D%5Bj%5D = true;%0A                    count++;%0A%0A                    int right = j + 1;%0A                    while (right %3C board%5Bi%5D.length && board%5Bi%5D%5Bright%5D == 'X') %7B%0A                        marked%5Bi%5D%5Bright%5D = true;%0A                        right++;%0A                    %7D%0A%0A                    int down = i + 1;%0A                    while (down %3C board.length && board%5Bdown%5D%5Bj%5D == 'X') %7B%0A                        marked%5Bdown%5D%5Bj%5D = true;%0A                        down++;%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        return count;
 %0A   

Solve problem 419