【二叉树的前序、中序、后序遍历的python写法】借助栈的实现,效率媲美递归~
# pythonic 无敌解法## 前序class Solution: def preorderTraversal(self, root: TreeNode) -> List[int]: stack, res = [root], [] while stack: i = stack.pop() if isinstance(i, TreeNode): stack.extend([i.
原创
2021-02-12 19:38:03 ·
150 阅读 ·
0 评论