my solution is :
but it doesn't work,what wrong with my code.
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.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.