Approx 0ms solution in c++ ,simple recursive code


  • 0
    R
    TreeNode* invertTree(TreeNode* root) {
            if(root==NULL) return NULL;
            TreeNode* lchild = invertTree(root->left);
            TreeNode* rchild=invertTree(root->right);
            root->right=lchild;
            root->left=rchild;
            return root;
        }

Log in to reply
 

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