链表
struct ListNode* removeElements(struct ListNode* head, int val) {
struct ListNode* head_ptr = (struct ListNode*)malloc(sizeof(struct ListNode));
head_ptr->next = head;
struct ListNode* p = head_ptr;
while(p->next != NULL)
{
if (p->next->val == val)
{
p->next = p->next->next;
//free(temp);
}
else
p = p->next;
}
//free(p);
return head_ptr->next;
}最后更新于