-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1669.cpp
More file actions
33 lines (31 loc) · 714 Bytes
/
1669.cpp
File metadata and controls
33 lines (31 loc) · 714 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
#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* mergeInBetween(ListNode* list1, int a, int b, ListNode* list2) {
ListNode* tmp = list1;
int i = 0;
while (i < a - 1) {
tmp = tmp->next;
i++;
}
ListNode* tmp2 = tmp;
while (i <= b) {
tmp2 = tmp2->next;
i++;
}
ListNode* tmp3 = list2;
while (tmp3->next != NULL) {
tmp3 = tmp3->next;
}
tmp3->next = tmp2;
tmp->next = list2;
return list1;
}
};