-
Notifications
You must be signed in to change notification settings - Fork 0
/
114.cpp
40 lines (35 loc) · 782 Bytes
/
114.cpp
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
32
33
34
35
36
37
38
39
40
#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
void helper(TreeNode* root,TreeNode* &store){
if(root->left==NULL && root->right==NULL){
store=root;
return;
}
if(root->left){
helper(root->left,store);
}
TreeNode* temp=root->right;
if(store!=NULL){
root->right=root->left;
store->right=temp;
}
root->left=NULL;
if(temp){
store=NULL;
helper(temp,store);
}
}
void flatten(TreeNode* root) {
if(root==NULL || (root->left==NULL && root->right==NULL)){
return;
}
TreeNode* store=NULL;
helper(root,store);
}
};
int main()
{
return 0;
}