simple and limited lines of Python solution


  • 0
    Z

    class Solution(object):
    def init(self):
    self.ans = []

    def postorderTraversal(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        
        """
        if root:
            self.postorderTraversal(root.left)
            self.postorderTraversal(root.right)
            self.ans.append(root.val)
            
        return self.ans
    

    It's intuitive and very easy to extend to pre-order and in-order solution


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.