Merge In Between Linked Lists

You are given two linked lists: list1 and list2. Remove list1's nodes from the a-th node to the b-th node and insert list2 into that position.

Constraints

  • 3 <= list1.length <= 10^4
  • 1 <= a <= b < list1.length - 1
  • 1 <= list2.length <= 10^4
Saving… · 9 lines
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next

class Solution:
def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode:

Console

Click Run to execute sample tests.