mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Update 二叉树的迭代遍历.md 调整注释内容
This commit is contained in:
@ -304,14 +304,14 @@ class Solution:
|
||||
```
|
||||
|
||||
#### Python 后序遍历的迭代新解法:
|
||||
* 本解法不同于前文介绍的`逆转前序遍历调整后的结果`,而是采用了对每个节点直接处理。
|
||||
* 本解法不同于前文介绍的`逆转前序遍历调整后的结果`,而是采用了对每个节点直接处理。这个实现方法在面试中不容易写出来,在下一节,我将改造本代码,奉上代码更简洁、更套路化、更容易实现的统一方法。
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def postorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
|
||||
values = []
|
||||
stack = []
|
||||
popped_nodes = set() # 记录值已经被收割了的 nodes
|
||||
popped_nodes = set() # 记录值已经被收割了的 nodes,这是关键,已经被收割的节点还在树中,还会被访问到,但逻辑上已经等同于 null 节点。
|
||||
current = root
|
||||
|
||||
while current or stack:
|
||||
|
Reference in New Issue
Block a user