forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
975e70f
commit 1e94bb2
Showing
1 changed file
with
9 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
### 529.Minesweeper | ||
|
||
此题首选BFS,基础题,但队列中的操作需要仔细考虑成熟。 | ||
|
||
我们点击一个格子,首先判断是否是M,是的话直接返回。 | ||
|
||
如果是非M,我们就考察周围8个格子,计算他们中间有地雷的个数。如果有地雷的话,那么就将这个格子标记数字,结束对这个格子的操作。特别注意,这个时候不能直接返回board,因为队列中还有很多各自没处理呢。如果一圈都没有地雷的话,就标记'B',并把这一圈的格子加入队列处理。 | ||
|
||
上面的操作可行,但是会MLE。一个格子A将周围的8个收入队列中,而它相邻的格子B也会将周围的8个收入队列中,会有大量的重复。所以需要一个visited来记录每个已经收入队列中的格子,已经收录的就不要再收了。 |