Tap here to switch tabs
Problem
Submissions

Problem: Battleships in a Board

med
30 min
Try to solve the Battleships in a Board problem.

Statement

Given an m $ imes$ n matrix board where each cell is either a battleship 'X' or empty '.', return the total number of battleships on board.

Battleships can only be placed horizontally or vertically. That is, a battleship has a size of 1imesk1 imes k (11 row, kk columns) or kimes1k imes 1 (kk rows, 11 column), where kk can be of any size. At least one horizontal or vertical empty cell separates any two battleships, meaning no two battleships are adjacent to each other.

Constraints:

  • m == board.length

  • n == board[i].length

  • 1≤1 \leq m, n ≤200\leq 200

  • board[i][j] is either '.' or 'X'

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Battleships in a Board

med
30 min
Try to solve the Battleships in a Board problem.

Statement

Given an m $ imes$ n matrix board where each cell is either a battleship 'X' or empty '.', return the total number of battleships on board.

Battleships can only be placed horizontally or vertically. That is, a battleship has a size of 1imesk1 imes k (11 row, kk columns) or kimes1k imes 1 (kk rows, 11 column), where kk can be of any size. At least one horizontal or vertical empty cell separates any two battleships, meaning no two battleships are adjacent to each other.

Constraints:

  • m == board.length

  • n == board[i].length

  • 1≤1 \leq m, n ≤200\leq 200

  • board[i][j] is either '.' or 'X'