Simple Python implementation


  • 0
    P
    EXPAND_NODE = 1
    READ_NODE = 2
    
    def iot(node):
        result = []
        q = [(EXPAND_NODE, node,)]
        while len(q) > 0:
            node_type, current_node = q.pop()
            if current_node == None:
                continue
    
            if node_type == EXPAND_NODE:
                q.append((EXPAND_NODE, current_node.right))
                q.append((READ_NODE, current_node))
                q.append((EXPAND_NODE, current_node.left))
            elif node_type == READ_NODE:
               result.append(current_node.val)
        return result

Log in to reply
 

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