@@ -0,0 +1,1830 @@
+package basic;%0A%0A/**%0ASource: https://leetcode.com/problems/battleships-in-a-board/%0A%0AGiven an 2D board, count how many different battleships are in it. %0AThe battleships are represented with 'X's, empty slots are represented with '.'s. %0AYou may assume the following rules:%0A%3Cbr%3E%0A%3Cli%3EYou receive a valid board, made of only battleships or empty slots.%3Cbr%3E%0A%3Cli%3EBattleships can only be placed horizontally or vertically. In other words, %0Athey can only be made of the shape 1xN (1 row, N columns) or Nx1 (N rows, 1 column), %0Awhere N can be of any size.%3Cbr%3E%0A%3Cli%3EAt least one horizontal or vertical cell separates between two %0Abattleships - there are no adjacent battleships.%3Cbr%3E%0A%3Cb%3EExample:%3C/b%3E%0AX..X%3Cbr%3E%0A...X%3Cbr%3E%0A...X%3Cbr%3E%0AIn the above board there are 2 battleships.%3Cbr%3E%0A%3Cb%3EInvalid Example:%3C/b%3E%3Cbr%3E%0A...X%3Cbr%3E%0AXXXX%3Cbr%3E%0A...X%3Cbr%3E%0AThis is an invalid board that you will not receive - as battleships will always%0Ahave a cell separating between them.%0A*/%0Apublic class BattleshipInBoardCounter%7B%0A  public int countBattleships(char%5B%5D%5B%5D board) %7B%0A        int count = 0;%0A        for (int i=0; i%3Cboard.length; i++)%7B%0A            for (int j=0; j%3Cboard%5Bi%5D.length; j++)%7B%0A                if (board%5Bi%5D%5Bj%5D == 'X')%7B%0A                    if (i==0)%7B%0A                        if (j==0)%7B%0A                            count++;%0A                        %7Delse if (board%5Bi%5D%5Bj-1%5D != 'X')%7B%0A                            count++;%0A                        %7D%0A                    %7Delse%7B%0A                        if (j==0)%7B%0A                            if (board%5Bi-1%5D%5Bj%5D !='X')%7B%0A                                count++;%0A                            %7D%0A                        %7Delse if (board%5Bi-1%5D%5Bj%5D != 'X' && board%5Bi%5D%5Bj-1%5D != 'X')%7B%0A                            count++;%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        return count;%0A    %7D%0A%7D%0A

Create BattleshipInBoardCounter.java