mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update 二叉树的统一迭代法.md 微调 stack 赋值语句
This commit is contained in:
@ -316,7 +316,7 @@ class Solution:
|
|||||||
class Solution:
|
class Solution:
|
||||||
def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
|
def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
|
||||||
values = []
|
values = []
|
||||||
stack = [] if root is None else [root]
|
stack = [root] if root else []
|
||||||
popped_nodes = set() # 用于记录一个节点是否被 pop() 过
|
popped_nodes = set() # 用于记录一个节点是否被 pop() 过
|
||||||
|
|
||||||
while stack:
|
while stack:
|
||||||
@ -345,7 +345,7 @@ class Solution:
|
|||||||
class Solution:
|
class Solution:
|
||||||
def postorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
|
def postorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
|
||||||
values = []
|
values = []
|
||||||
stack = [] if root is None else [root]
|
stack = [root] if root else []
|
||||||
popped_nodes = set() # 用于记录一个节点是否被 pop() 过
|
popped_nodes = set() # 用于记录一个节点是否被 pop() 过
|
||||||
|
|
||||||
while stack:
|
while stack:
|
||||||
|
Reference in New Issue
Block a user