/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* removeElements(ListNode* head, int val) {
ListNode *pre=NULL;
ListNode *scan=head;
if(!scan)
return scan;
while(scan)
{
if(scan->val==val)
{
if(head==scan)
head=head->next;
else
pre->next=pre->next->next;
}
else
pre=scan;
scan=scan->next;
}
return head;
}
};
203. Remove Linked List Elements
最新推荐文章于 2022-02-11 19:44:01 发布