Minesweeper

You are given an m x n char matrix board representing a Minesweeper game board. Characters 'M' and 'E' represent unrevealed mine and unrevealed empty square, respectively. 'B' stands for a revealed blank with no adjacent mines, while digits from '1' to '8' indicate the number of adjacent mines. 'X' is a revealed mine. Given an integer array click representing the next click position on 'M' or 'E', return the board after revealing this position. If a mine 'M' is revealed, it changes to 'X'. If an empty square 'E' with no adjacent mines is revealed, it should become 'B', and all adjacent unrevealed squares should be revealed recursively. If 'E' with adjacent mines is revealed, it changes to a digit representing the number of adjacent mines. Return the board when no more squares will be revealed.

Constraints

  • m == board.length
  • n == board[i].length
  • 1 <= m, n <= 50
  • board[i][j] is either 'M', 'E', 'B', or a digit from '1' to '8'.
  • click.length == 2
  • 0 <= click[r] < m
  • 0 <= click[c] < n
  • board[click[r]][click[c]] is either 'M' or 'E'.
Saving… · 2 lines
class Solution:
def minesweeper(self, board: List[List[str]], click: List[int]) -> List[List[str]]:
Console

Click Run to execute sample tests.