-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path203.cpp
31 lines (30 loc) · 858 Bytes
/
203.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*************************************************************************
> File Name: 203.cpp
> Author: 北海望谷堆
> Mail: [email protected]
> Created Time: Tue 09 Jun 2020 06:13:14 PM CST
************************************************************************/
/**
* 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) {
if (!head) return head;
ListNode *phead = new ListNode(0);
phead->next = head;
head = phead;
ListNode *p = head;
while (p->next) {
if (p->next->val == val) {
p->next = p->next->next;
} else p = p->next;
}
return head->next;
}
};