Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
LeetCodeAnimation
Commits
1c379889
Commit
1c379889
authored
Apr 20, 2020
by
xiaoshuai96
Browse files
solved @xiaoshuai96
parent
650eeb55
Changes
3
Hide whitespace changes
Inline
Side-by-side
0994-orangesRotting/Animation/example.png
→
0994-orangesRotting/Animation/example
01
.png
View file @
1c379889
File moved
0994-orangesRotting/Animation/腐烂的橘子.gif
→
0994-orangesRotting/Animation/腐烂的橘子
01
.gif
View file @
1c379889
File moved
0994-orangesRotting/Article/0994-orangesRotting.md
View file @
1c379889
...
...
@@ -39,12 +39,12 @@
思路是非常简单的,我们通过动态图直观理解下:


既然理清了思路,那么我们来试试代码:
首先,我们需要知道初始状态下的单元格中有多少腐烂的橘子,并且要将它们的位置信息保存下来,我们可以用一个队列(
**先入先出**
)将(x,y)保存下来;然后我们开始遍历整个队列,每次弹出一个保存的位置信息,将这个位置周围的新鲜橘子全部腐蚀,然后把该位置的信息从队列中删除(旧的信息在下次腐蚀中已经没用了),并且将被腐蚀的橘子的位置信息存入队列中,在下次循环中从它们的位置上再“
**向外延伸**
”;直到队列为空,循环结束,这个时候并不能说明整个单元格中已经不存在新鲜的橘子,因为可能存在下面这种情况:


很明显,标红的区域(新鲜橘子)永远不能被腐蚀,因为它周围唯一的两个单元格是空的。
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment