```
class Solution {
public:
TreeNode *flattenHelper(TreeNode *root) {
if (NULL == root) {
return NULL;
}
if (NULL == root->left && NULL == root->right) {
return root;
}
if (root->left) {
TreeNode *leftButtomNode = flattenHelper(root->left);
leftButtomNode->right = root->right;
root->right = root->left;
root->left = NULL;
}
return flattenHelper(root->right);
}
void flatten(TreeNode* root) {
flattenHelper(root);
}
};
```