```
class Solution {
public:
TreeNode* upsideDownBinaryTree(TreeNode* root) {
if(!root || !root -> left) return root;
auto ret = root -> left;
while(ret -> left) ret = ret -> left;
upsideDownBinaryTree(root -> left);
auto temp = root -> right;
root -> left -> left = root -> right;
root -> left -> right = root;
root -> left = NULL;
root -> right = NULL;
return ret;
}
};
```