We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2e9e92e commit ef39957Copy full SHA for ef39957
1490-clone-n-ary-tree.js
@@ -0,0 +1,20 @@
1
+/**
2
+ * // Definition for a Node.
3
+ * function Node(val, children) {
4
+ * this.val = val === undefined ? 0 : val;
5
+ * this.children = children === undefined ? [] : children;
6
+ * };
7
+ */
8
+
9
10
+ * @param {Node} node
11
+ * @return {Node}
12
13
+const cloneTree = function(root) {
14
+ if(root == null) return null
15
+ let node = new Node(root.val)
16
+ for(let i = 0, len = root.children.length; i < len; i++) {
17
+ node.children.push(cloneTree(root.children[i]))
18
+ }
19
+ return node
20
+};
0 commit comments