-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20mar.txt
39 lines (31 loc) · 859 Bytes
/
20mar.txt
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
class Solution {
public:
ListNode* mergeInBetween(ListNode* list1, int a, int b, ListNode* list2) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ListNode *temp1 = list1;
ListNode *prev = list1;
ListNode *temp2 = list1;
ListNode *tail = list2;
int index = 0;
while(temp1 != 0 and index < a)
{
prev = temp1;
temp1 = temp1->next;
index++;
}
index = 0;
while(temp2 != 0 and index < b)
{
temp2 = temp2->next;
index++;
}
while(tail != 0 and tail->next != 0)
tail = tail->next;
cout << prev->val << " " << temp2->val << endl;
prev->next = list2;
tail->next = temp2->next;
return list1;
}
};