I solve this problem with no use of stack.

Please let me know if there is any problem.

```
void flatten(TreeNode *root) {
while(root){
TreeNode* tmp = root->right;
root->right = root->left;
root->left = nullptr;
TreeNode* curr = root;
while(curr->right){
curr = curr->right;
}
curr->right = tmp;
root = root->right;
}
}
```