How to handle a input without element? just like []

  • 0

    my solution is :

       return head;

    but it doesn't work,what wrong with my code.

  • 0


    The exception happens when the head is NULL. If the head is NULL, it is mem violation to access head->next.
    The right thing to do is if( head == NULL || head->next==NULL) so if the first clause is true, the second is not evaluated.

Log in to reply

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