529. Minesweeper Medium
1/**
2 * [529] Minesweeper
3 *
4 * Let's play the minesweeper game (<a href="https://en.wikipedia.org/wiki/Minesweeper_(video_game)" target="_blank">Wikipedia</a>, <a href="http://minesweeperonline.com" target="_blank">online game</a>)!
5 * You are given an m x n char matrix board representing the game board where:
6 *
7 * 'M' represents an unrevealed mine,
8 * 'E' represents an unrevealed empty square,
9 * 'B' represents a revealed blank square that has no adjacent mines (i.e., above, below, left, right, and all 4 diagonals),
10 * digit ('1' to '8') represents how many mines are adjacent to this revealed square, and
11 * 'X' represents a revealed mine.
12 *
13 * You are also given an integer array click where click = [clickr, clickc] represents the next click position among all the unrevealed squares ('M' or 'E').
14 * Return the board after revealing this position according to the following rules:
15 * <ol>
16 * If a mine 'M' is revealed, then the game is over. You should change it to 'X'.
17 * If an empty square 'E' with no adjacent mines is revealed, then change it to a revealed blank 'B' and all of its adjacent unrevealed squares should be revealed recursively.
18 * If an empty square 'E' with at least one adjacent mine is revealed, then change it to a digit ('1' to '8') representing the number of adjacent mines.
19 * Return the board when no more squares will be revealed.
20 * </ol>
21 *
22 * Example 1:
23 * <img src="https://assets.leetcode.com/uploads/2018/10/12/minesweeper_example_1.png" style="width: 500px; max-width: 400px; height: 269px;" />
24 * Input: board = [["E","E","E","E","E"],["E","E","M","E","E"],["E","E","E","E","E"],["E","E","E","E","E"]], click = [3,0]
25 * Output: [["B","1","E","1","B"],["B","1","M","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]]
26 *
27 * Example 2:
28 * <img src="https://assets.leetcode.com/uploads/2018/10/12/minesweeper_example_2.png" style="width: 500px; max-width: 400px; height: 275px;" />
29 * Input: board = [["B","1","E","1","B"],["B","1","M","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]], click = [1,2]
30 * Output: [["B","1","E","1","B"],["B","1","X","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]]
31 *
32 *
33 * Constraints:
34 *
35 * m == board.length
36 * n == board[i].length
37 * 1 <= m, n <= 50
38 * board[i][j] is either 'M', 'E', 'B', or a digit from '1' to '8'.
39 * click.length == 2
40 * 0 <= clickr < m
41 * 0 <= clickc < n
42 * board[clickr][clickc] is either 'M' or 'E'.
43 *
44 */
45pub struct Solution {}
46
47// problem: https://leetcode.com/problems/minesweeper/
48// discuss: https://leetcode.com/problems/minesweeper/discuss/?currentPage=1&orderBy=most_votes&query=
49
50// submission codes start here
51
52impl Solution {
53 pub fn update_board(board: Vec<Vec<char>>, click: Vec<i32>) -> Vec<Vec<char>> {
54 vec![]
55 }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn test_529() {
66 }
67}
68
Back
© 2025 bowen.ge All Rights Reserved.