A Solution in Python

  • 0

    class Solution(object):
    def countBattleships(self, board):
    :type board: List[List[str]]
    :rtype: int
    count = 0
    row,col = len(board), len(board[0])
    for i in range(row):
    for j in range(col):
    if board[i][j] == 'X':
    if (j-1 >= 0 and board[i][j-1] == 'X') or (i-1 >= 0 and board[i-1][j] =='X'):
    count += 1
    return count

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.