C++ recursive solution


  • 0
    P
    class Solution {
    public:
        TreeNode* upsideDownBinaryTree(TreeNode* root) {
            if(!root || !root->left) return root;
            TreeNode *new_tree = upsideDownBinaryTree(root->left);
            root->left->left = upsideDownBinaryTree(root->right);
            root->left->right = root;
            root->left = root->right = NULL;
            return new_tree;
        }
    };

Log in to reply
 

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