Battleships in a Board LeetCode solution in Python
1class Solution:2def countBattleships(self, board: List[List[str]]) -> int:34m = len(board)5n = len(board[0])6res = 078pole = [[True for i in range(n)] for j in range(m)]910for i in range(m):11for j in range(n):12if board[i][j] == "X" and pole[i][j]:13for z in range(i + 1, m):14if board[z][j] == "X":15pole[z][j] = False16else:17break1819for z in range(j + 1, n):20if board[i][z] == "X":21pole[i][z] = False22else:23break2425res += 12627return res