It is very basic to delete the value of the linked list val Node of , This is a simple question , But I didn't write it right at first ...
/** * Definition for singly-linked list. * struct ListNode { * int val; *
struct ListNode *next; * }; */ struct ListNode* removeElements(struct ListNode*
head, int val) { struct ListNode* p = (struct ListNode*)malloc(sizeof(struct
ListNode));//struct ListNode* p = malloc(sizeof(struct ListNode)); There is also this way of writing
p->next = head; struct ListNode* temp = p; while (temp->next != NULL) { if
(temp->next->val == val) { temp->next = temp->next->next; } else { temp =
temp->next; } } return p->next; }
* Return value problem , By all means p->next, because p->next and head Not necessarily equal .([7,7,7,7,7])
*
When setting the header node , Be sure to apply for space first . This kind of writing is also OK struct ListNode* p = malloc(sizeof(struct ListNode));( I haven't seen it before , I was stunned )

Technology