```
class Solution {
public:
void flatten(TreeNode* root)
{
if(!root) return;
flatten(root->left), flatten(root->right);
if(!root->left) return;
TreeNode * temp = root;
while(temp -> left) temp = temp -> left;
while(temp->right) temp = temp->right;
temp -> right = root -> right;
root -> right = root -> left;
root -> left = NULL;
}
};
```