Update 二叉树的统一迭代法.md 微调 stack 赋值语句
This commit is contained in:
parent
b8a4613c53
commit
a8ac9f9ae0
|
|
@ -316,7 +316,7 @@ class Solution:
|
|||
class Solution:
|
||||
def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
|
||||
values = []
|
||||
stack = [] if root is None else [root]
|
||||
stack = [root] if root else []
|
||||
popped_nodes = set() # 用于记录一个节点是否被 pop() 过
|
||||
|
||||
while stack:
|
||||
|
|
@ -345,7 +345,7 @@ class Solution:
|
|||
class Solution:
|
||||
def postorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
|
||||
values = []
|
||||
stack = [] if root is None else [root]
|
||||
stack = [root] if root else []
|
||||
popped_nodes = set() # 用于记录一个节点是否被 pop() 过
|
||||
|
||||
while stack:
|
||||
|
|
|
|||
Loading…
Reference in New Issue