-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path375.h
More file actions
31 lines (27 loc) · 644 Bytes
/
375.h
File metadata and controls
31 lines (27 loc) · 644 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Definition of TreeNode:
* class TreeNode {
* public:
* int val;
* TreeNode *left, *right;
* TreeNode(int val) {
* this->val = val;
* this->left = this->right = NULL;
* }
* }
*/
class Solution {
public:
/*
* @param root: The root of binary tree
* @return: root of new tree
*/
TreeNode * cloneTree(TreeNode * root) {
// write your code here
if(root == nullptr) return nullptr;
TreeNode *node = new TreeNode(root->val);
node->left = cloneTree(root->left);
node->right = cloneTree(root->right);
return node;
}
};