Skip to content

Instantly share code, notes, and snippets.

@minhntm
Last active February 16, 2020 13:51
Show Gist options
  • Save minhntm/8b55e805881d7b800a014bf2bd528716 to your computer and use it in GitHub Desktop.
Save minhntm/8b55e805881d7b800a014bf2bd528716 to your computer and use it in GitHub Desktop.
Minesweeper
class Solution:
def updateBoard(self, board: List[List[str]], click: List[int]) -> List[List[str]]:
y = click[0]
x = click[1]
if board[y][x] == 'M':
board[y][x] = 'X'
return board
adjacent_mines = 0
for i in range(y-1, y+2):
for j in range(x-1, x+2):
if len(board) > i >= 0 and len(board[0]) > j >= 0 and board[i][j] == 'M':
adjacent_mines = adjacent_mines + 1
if adjacent_mines == 0:
board[y][x] = 'B'
for i in range(y-1, y+2):
for j in range(x-1, x+2):
if len(board) > i >= 0 and len(board[0]) > j >= 0 and board[i][j] == 'E':
self.updateBoard(board, [i, j])
else:
board[y][x] = str(adjacent_mines)
return board
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment