python solution using two stacks


  • 0
    A
    class Solution(object):
        def postorderTraversal(self, root):
            if root == None:
                return []
                
            s1 = []
            s2 = []
            
            s1.append(root)
            
            while s1:
                node = s1.pop()
                s2.insert(0, node.val)
                
                if node.left:
                    s1.append(node.left)
                if node.right:
                    s1.append(node.right)
                    
            return s2
            
    

Log in to reply
 

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