Description

Count battleships on a board. Battleships are represented by X. They can only be placed horizontally or vertically with spaces between them.

Examples

Input:board = [["X",".",".","X"],[".",".",".","X"],[".",".",".","X"]]
Output:2
Explanation:

Two battleships.

Input:board = [[1]]
Output:1
Explanation:

Minimal case with a single-element matrix.

Input:board = [["X","X",".","X"],[".",".",".","."],[".",."X","X","X"],["X",".",".","."]]
Output:3
Explanation:

There are three battleships: one horizontal battleship in the first row (positions [0,0] and [0,1]), one horizontal battleship in the third row (positions [2,1], [2,2], and [2,3]), and one single-cell battleship at position [3,0]. The isolated 'X' at [0,3] forms another single-cell battleship, making it 4 total battleships.

Constraints

  • 1 ≤ m, n ≤ 200

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!