Update 二叉树的统一迭代法.md 微调 stack 赋值语句

This commit is contained in:
Lane Zhang (张健)
2024-10-24 09:15:07 +08:00
committed by GitHub
parent b8a4613c53
commit a8ac9f9ae0

View File

@ -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: