Simple concise python reverse list solution


  • 0
    M
    def postorderTraversal(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        """
        if root == None:
            return []
        
        stack = []
        stack.append(root)
        result = []
        
        while(len(stack)>0):
            pop = stack.pop()
            result.append(pop.val)
            
            if pop.left != None:
                stack.append(pop.left)
            if pop.right != None:
                stack.append(pop.right)
        
        return list(reversed(result))

Log in to reply
 

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