Skip to content

Commit 454d5db

Browse files
added daily challenge
1 parent 47ab26b commit 454d5db

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, val=0, next=None):
4+
# self.val = val
5+
# self.next = next
6+
class Solution:
7+
def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode:
8+
prev = list1
9+
temp1 = list1
10+
curr = list1
11+
a -= 1
12+
13+
while temp1 and a > 0:
14+
temp1 = temp1.next
15+
prev = temp1
16+
a -= 1
17+
18+
temp1 = list1
19+
20+
21+
while temp1 and b > 0:
22+
temp1 = temp1.next
23+
curr = temp1
24+
b -= 1
25+
26+
temp2 = list2
27+
28+
while temp2.next:
29+
temp2 = temp2.next
30+
31+
prev.next = list2
32+
temp2.next = curr.next
33+
34+
return list1

0 commit comments

Comments
 (0)