写了个递归
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* delect(struct ListNode* head,int x){
if(!head) return NULL;
if(head->val==x){
struct ListNode* tem=head;
head=head->next;
free(tem);
head=delect(head,x);
}else{
head->next=delect(head->next,x);
}
return head;
}
struct ListNode* removeElements(struct ListNode* head, int val) {
return delect(head,val);
}
结果: