forked from illuz/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAC_simulation_n.cpp
More file actions
45 lines (36 loc) · 850 Bytes
/
Copy pathAC_simulation_n.cpp
File metadata and controls
45 lines (36 loc) · 850 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_simulation_n.cpp
* Create Date: 2015-04-23 22:29:40
* Descripton:
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
// 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 dummy(0);
dummy.next = head;
ListNode* cur = &dummy;
while (cur->next != nullptr) {
if (cur->next->val == val) {
ListNode* dup = cur->next;
cur->next = dup->next;
delete dup;
} else {
cur = cur->next;
}
}
return dummy.next;
}
};
int main() {
return 0;
}