Back to course home
0% completed
Clone N-ary Tree (hard)
Problem Statement
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.
Examples
Example 1
- Input:
root = [1, null, 2, 3, 4, 5, null, 6, 7, null, 8]
- Expected Output:
[1, null, 2, 3, 4, 5, null, 6, 7, null, 8]
- Justification:
- The tree has multiple levels, where each node has a different number of children
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible