togepy
Senior Member
Python:
class Solution:
def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode:
count = 0
cur = list1
temp1 = cur
temp2 = cur
while cur is not None:
if count == a - 1:
temp1 = cur
if count == b:
temp2 = cur.next
break
cur = cur.next
count += 1
temp3 = list2
while temp3.next is not None:
temp3 = temp3.next
temp1.next = list2
temp3.next = temp2
return list1