0
点赞
收藏
分享

微信扫一扫

145. 二叉树的后序遍历

145. 二叉树的后序遍历_链表

# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def postorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
res = []
def tail(root):
if not root:
return None
tail(root.left) # 左右后
tail(root.right)
res.append(root.val)

tail(root)
return res


举报

相关推荐

0 条评论