python recursive solution


  • 0
    A
    class Solution(object):
        def updateBoard(self, board, click):
            (row,column)=click
            direction=((-1,0),(1,0),(0,1),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1))
            
            if row in range(len(board)) and column in range(len(board[0])):
                if board[row][column]=='M':
                    board[row][column]='X'
                elif board[row][column]=='E':
                    n=sum(board[row+r][column+c]=='M' for r,c in direction if row+r in range(len(board)) and column+c in range(len(board[0])))
                    board[row][column]=str(n or 'B')
                    if not n:
                        for r,c in direction: 
                            self.updateBoard(board,(row+r,column+c)) 
            return board
    
    

Log in to reply
 

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