my iterative solution in python


  • 0
    A
    class Solution(object):
        def inorderTraversal(self, root):
            result = []
            
            if root == None:
                return result
                
            stack = []
            
            while True:
                if root:
                    stack.append(root)
                    root = root.left
                else:
                    if not stack:
                        break
                    root = stack.pop()
                    result.append(root.val)
                    root = root.right
                    
            return result
    

Log in to reply
 

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