# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param root TreeNode类 
# @return int整型一维数组
#
class Solution:
    def postorderTraversal(self , root: TreeNode) -> List[int]:
        # 前中后序遍历都需要用递归!!!

        if not root:
            return []
        
        # 后序遍历:左右根。
        # 递归遍历左子树。
        current_left = self.postorderTraversal(root.left)
        # 递归遍历右子树。
        current_right = self.postorderTraversal(root.right)
        # 读取当前根节点的值。
        current_root = [root.val]

        # python中可以用‘+’来合并多个列表。
        return current_left + current_right + current_root