#后序遍历二叉树递归法
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution:
    def postorderTraversal(self, root: TreeNode):
        ans = []
        self.postorder(root, ans)
        return ans
    def postorder(self, root, ans):
        if not root:
            return
        self.postorder(root.left, ans)
        self.postorder(root.right, ans)
        ans.append(root.val)
e268969e071eee0f6900946ab5ee104591b0e195
<mask token>


class Solution:

    def postorderTraversal(self, root: TreeNode):
        ans = []
        self.postorder(root, ans)
        return ans
    <mask token>

<mask token>


class Solution:

    def postorderTraversal(self, root: TreeNode):
        ans = []
        self.postorder(root, ans)
        return ans

    def postorder(self, root, ans):
        if not root:
            return
        self.postorder(root.left, ans)
        self.postorder(root.right, ans)
        ans.append(root.val)

class TreeNode:
    <mask token>


class Solution:

    def postorderTraversal(self, root: TreeNode):
        ans = []
        self.postorder(root, ans)
        return ans

    def postorder(self, root, ans):
        if not root:
            return
        self.postorder(root.left, ans)
        self.postorder(root.right, ans)
        ans.append(root.val)

class TreeNode:

    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:

    def postorderTraversal(self, root: TreeNode):
        ans = []
        self.postorder(root, ans)
        return ans

    def postorder(self, root, ans):
        if not root:
            return
        self.postorder(root.left, ans)
        self.postorder(root.right, ans)
        ans.append(root.val)

#后序遍历二叉树递归法
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution:
    def postorderTraversal(self, root: TreeNode):
        ans = []
        self.postorder(root, ans)
        return ans
    def postorder(self, root, ans):
        if not root:
            return
        self.postorder(root.left, ans)
        self.postorder(root.right, ans)
        ans.append(root.val)