Given all the nodes of an N-ary
tree as an array Node[] tree
where each node has a unique
value.
Find and return the root of the N-ary tree.
Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).
Follow up: Can you find the root of the tree with O(1) additional memory space?
Notes:
Example 1:
Input: [1,null,3,2,4,null,5,6] Output: [1,null,3,2,4,null,5,6]
Example 2:
Input: [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14] Output: [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]
Constraints:
[1, 5*10^4]
.