My accepted solution in python


  • 5
    S
    class Solution:
        def inorderTraversal(self, root):
            stack = []
            output = []
            while True:
                while root:
                    stack.append(root)
                    root = root.left
                if stack == []:
                    break
                node = stack.pop()
                output.append(node.val)
                root = node.right
            return output

  • 0
    S

    Thanks for your post. However it would be better to share solution with correct code format and elaborated thoughts. Please read the Discuss FAQ for more info. Take a look at good sharing example


Log in to reply
 

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