Can anyone tell me what this serialized tree is represented in a tree form?


  • 0
    B

    {-1,#,0,1,#,2,3,4,5,#,6,7,8,9,10,11,12,13,#}

    I am very new to tree serialization... i have no idea what it looks like, and I can't follow the explanations on leetcode site that explains it.

    Thanks!


  • 1
    M

    {-1,#,0,1,#,2,3,4,5,#,6,7,8,9,10,11,12,13,#}

    It's a level order traversal, where the # means it's a null node, and the indices that would be its descendents are not included in the array.

            -1
            / \
           #   0
              / \
             1   #
           /  \
          2     3
         / \   / \
        4   5 #   6
       / \ / \    / \
      7  8 9 10  11  12
     / \
    13  # 
    

    EDIT Just remembered that this problem uses a different format for the serialization. The above assumes that the tree uses the normal serialization for Input. The alternative for this problem is as follows:

              -1 -> #
           /     \
         0         1 -> #
       /   \      /  \
      2     3    4     5 -> #
     / \   / \  / \   / \
    6   7 8  9 10 11 12 13 -> #

Log in to reply
 

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