题目:
python3代码:
# 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: TreeNode) -> List[int]:
if not root:
return list() # 或者 return []
res = []
self.postTraversal(root, res)
return res
def postTraversal(self, root, res):
if root:
self.postTraversal(root.left, res)
self.postTraversal(root.right, res)
res.append(root.val)
如果觉得不错,就点赞关注留言吧~
谢谢~