I'm confusing on the input {1, #, 2, #, 3}


  • 1
    N

    if # represents NULL pointer, so I think {1, #, 2, #, 3} should represent the binary tree as below:

                 1
              /     \
            #         2 
         /     \
       #         3
    

    But how the NULL pointer can have a right child 3?


  • 6

    No, the NULL pointer cannot have a right child. Therefore, we skip NULL nodes when going to the next level.

    The input tree should look like following:

                 1
              /     \
            #         2 
                    /    \
                  #       3

  • 0
    W

    first, i think {1, #, 2, #, 3} represent the complete preorder traverse binary tree sequence

    second, i think this seq will be more clear, {1, #, 2, #, 3, #, #}


Log in to reply
 

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