Super Simple Iterative Python Solution


  • 0
        def preorderTraversal(self, root):
            res = []
            stack = []
            curr = root
            while stack or curr:
                while curr:
                    res.append(curr.val)
                    stack.append(curr)
                    curr = curr.left
                if stack:
                    curr = stack.pop().right
            return res
            
    

Log in to reply
 

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