Wondering if directly modify root->left and root->right changes the original tree?


  • 0
    Y

    Hi, I've tried C++ recursive solution but it seems a lot fast solution(13-16ms) has using the following statement to return result rather than explicit new one, I'm wondering if this will change the original tree so it's not a good answer in real life?

        root->left = trimBST(root->right, L, R);
        root->right =trimBST(root->right, L, R);
        return root;
     
    Thanks,

Log in to reply
 

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