C++ recursive solution


  • 0
    B
    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;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.