-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path203.cpp
More file actions
35 lines (29 loc) · 756 Bytes
/
203.cpp
File metadata and controls
35 lines (29 loc) · 756 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
// 203. Remove Linked List Elements - https://leetcode.com/problems/remove-linked-list-elements
#include "bits/stdc++.h"
using namespace std;
// 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) {
auto dummy = new ListNode(0);
auto result = dummy;
auto cur = head;
while (cur != nullptr) {
if (cur->val != val) {
dummy = dummy->next = cur;
}
cur = cur->next;
}
dummy->next = nullptr;
return result->next;
}
};
int main() {
ios::sync_with_stdio(false);
return 0;
}