Recursive c++ 0ms


  • 0
    H
    TreeNode* invertTree(TreeNode* root)
    {
        if( root == nullptr ) return nullptr;
        
        //! swap
        TreeNode *pTemp = root->right;
        root->right = root->left;
        root->left = pTemp;
        
        invertTree(root->left);
        invertTree(root->right);
        return root;
    }
    

    this leads 0ms in all test cases.
    (maybe direct swap is more efficient than swap() ?)


Log in to reply
 

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