Skip to content

Latest commit

 

History

History
31 lines (26 loc) · 738 Bytes

419.md

File metadata and controls

31 lines (26 loc) · 738 Bytes
class Solution(object):
    def countBattleships(self, board):
        """
        :type board: List[List[str]]
        :rtype: int
        """
        if len(board) == 0:
            return 0
        if len(board[0]) == 0:
            return 0
        
        ans = 0
        
        for i in range(len(board)):
            for j in range(len(board[0])):
                if board[i][j] == 'X':
                    if i > 0:
                        if board[i-1][j] == 'X':
                            continue
                    if j > 0:
                        if board[i][j-1] == 'X':
                            continue
                    ans += 1
                    
        return ans

battleship 战舰

扫描