title | tags | grammar_cjkRuby |
---|---|---|
203-remove-linked-list-elements |
在河之洲,算法,小书匠 |
true |
203-remove-linked-list-elements
ListNode* removeElements(ListNode* head, int val) {
if (head == NULL)
return NULL;
ListNode *dummy = new ListNode(0);
dummy->next = head;
ListNode *cur = dummy;
while (cur->next !=NULL)
{
if (cur->next->val == val)
{
ListNode *tmp = cur->next;
cur->next = tmp->next;
delete tmp;
}
else
{
cur = cur->next;
}
}
return dummy->next;
}