Battleships in a Board

Given a matrix representing a battleship board, count the number of battleships present. Battleships are placed horizontally or vertically and are not adjacent to each other.

Constraints

  • m == board.length
  • n == board[i].length
  • 1 <= m, n <= 200
  • board[i][j] is either '.' or 'X'.
Saving… · 2 lines
class Solution:
def countBattleships(self, board: List[List[str]]) -> int:
Console

Click Run to execute sample tests.