File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,10 @@ class Solution:
157157
158158我们可以使用一种叫做 Morris 遍历的方法,既不使用递归也不借助于栈。从而在 $O(1)$ 空间完成这个过程。
159159
160+ ** 如果你需要使用 $O(1)$ 空间遍历一棵二叉树,那么就要使用 Morris 遍历。**
161+
162+ 这个算法考察相对少,作为了解即可。
163+
160164``` python
161165def MorrisTraversal (root ):
162166 curr = root
@@ -197,7 +201,17 @@ def MorrisTraversal(root):
197201
198202参考: [ what-is-morris-traversal] ( https://www.educative.io/edpresso/what-is-morris-traversal )
199203
200- ** 划重点:Morris 是一种可以在 $O(1)$ 空间遍历二叉树的算法。\* **
204+ ** 划重点:Morris 是一种可以在 $O(1)$ 空间遍历二叉树的算法。**
205+
206+ ## 总结
207+
208+ 本文详细讲解了二叉树的层次遍历和深度优先遍历。
209+
210+ 对于深度优先遍历,我们又细分为前中后序三种遍历方式。
211+
212+ 最后我们讲解了双色遍历和 Morris 遍历。这两种方式可以作为了解,不掌握也没关系。
213+
214+ 另外,如果题目要求你实现迭代器(就是调用一次输出一个二叉树的值),那么前面讲的迭代的方式就非常适用了。比如这道题 [ Binary Search Tree Iterator] ( https://binarysearch.com/problems/Binary-Search-Tree-Iterator )
201215
202216## 相关专题
203217
You can’t perform that action at this time.
0 commit comments