Simple PYTHON


  • 0
    P
    class Solution(object):
        def updateBoard(self, board, click):
            n, m = len(board), len(board[0])
            click = [click]
            while len(click):
                c = click.pop()
                if board[c[0]][c[1]] == 'M':
                    board[c[0]][c[1]] = 'X'
                    return board
                if board[c[0]][c[1]] == 'E':
                    mList = [[c[0]+i, c[1]+j] for i in range(-1, 2) for j in range(-1, 2)
                                 if n > c[0]+i >= 0 and m > c[1]+j >= 0 and (i, j) != (0, 0) and board[c[0]+i][c[1]+j] == 'M']
                    nMines = len(mList)
                    board[c[0]][c[1]] = 'B'*(nMines == 0) or str(nMines)
                    if nMines == 0:
                        eList = [[c[0] + i, c[1] + j] for i in range(-1, 2) for j in range(-1, 2)
                                 if n > c[0] + i >= 0 and m > c[1] + j >= 0 and (i, j) != (0, 0) and board[c[0]+i][c[1]+j] == 'E']
                        click.extend(eList)
            return board
    

Log in to reply
 

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