-
/**
-
* Definition for binary tree
-
* struct TreeNode {
-
* int val;
-
* TreeNode *left;
-
* TreeNode *right;
-
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
-
* };
-
*/
-
class Solution {
-
public:
-
void flatten(TreeNode *root) {
-
// Note: The Solution object is instantiated only once and is reused by each test case.
-
if(NULL==root) return;
-
flatten(root->left);
-
flatten(root->right);
-
if(NULL==root->left) return;
-
TreeNode *tmp=root->left;
-
while(tmp->right) tmp=tmp->right;
-
tmp->right=root->right;
-
root->right=root->left;
-
root->left=NULL;
-
}
-
};