I don't know why the result of subit is "member access within null pointer of type 'struct ListNode'". I tested the sample and the capital was correct, I don't know what is wrong with my cognition of the empty indicators, can someone help me?
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* deleteDuplicates(struct ListNode* head){
struct ListNode* node = head;
while(node->next != NULL && node != NULL){
if(node->val == node->next->val){
struct ListNode* duplicate = node->next;
node->next = node->next->next;
free(duplicate);
}
else node = node->next;
}
return head;
}