Simple and clear iterative python solution


  • 0
    T
    class Solution:
        # @param {TreeNode} root
        # @return {integer[]}
        def inorderTraversal(self, root):
            stack, result = [(False, root),], []
            while stack:
                read, node = stack.pop()
                if node:
                    if not read:
                        stack.append((False, node.right))
                        stack.append((True, node))
                        stack.append((False, node.left))
                    else:
                        result.append(node.val)
            return result

Log in to reply
 

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