-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19.cpp
More file actions
27 lines (26 loc) · 665 Bytes
/
19.cpp
File metadata and controls
27 lines (26 loc) · 665 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
#include <bits/stdc++.h>
#include "ListNode.cpp"
using namespace std;
class Solution {
public:
Solution() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ListNode* removeNthFromEnd(ListNode* head, int n) {
ListNode* dummy = new ListNode(0);
dummy->next = head;
ListNode* first = dummy;
ListNode* second = dummy;
for (int i = 1; i <= n + 1; i++) {
first = first->next;
}
while (first != nullptr) {
first = first->next;
second = second->next;
}
second->next = second->next->next;
return dummy->next;
}
};