0% completed
Given the root
of an N-ary tree
, return a deep copy (clone) of this tree.
Each node in the N-ary tree has an integer value (val
) and a list of its children (children
). The deep copy should have the exact structure and values as the original tree but should not share any references with it.
root = [1, null, 2, 3, 4, 5, null, 6, 7, null, 8]
[1, null, 2, 3, 4, 5, null, 6, 7, null, 8]
root = [7, null, 9, null, 11, 12, null, 14, 15, null, 16]
[7, null, 9, null, 11, 12, null, 14, 15, null, 16]
root = [4, null, 5, 6, 7, 8, null, 9, null, 10, 11, 12]
[4, null, 5, 6, 7, 8, null, 9, null, 10, 11, 12]
Constraints:
Try solving this question here:
.....
.....
.....