My accepted code in Python


  • 2
    X
    class Solution:
        # @param root, a tree node
        # @return a list of integers
        def inorderTraversal(self, root):
            if root == None:
                return []
            result = []
            visited = []
            stack = [root]
            while stack != []:
                node = stack.pop()
                if node in visited:
                    result.append(node.val)
                    continue
                visited.append(node)
                if node.right != None:
                    stack.append(node.right)
                stack.append(node)
                if node.left != None:
                    stack.append(node.left)
            return result

  • 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.