Simple recursive solution


  • 0
    L
        TreeNode* invertTree(TreeNode* root) {
            if (root) {
                TreeNode *right = root->right, *left= root->left;
                root->right = invertTree(left);
                root->left = invertTree(right);
            } 
            return root;
        }
    

Log in to reply
 

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