# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
index1=l1
index2=l2
head=ListNode(0)
cur=head
if index1 and not index2:
return index1
if index2 and not index1:
return index2
while(index1 and index2):
if index1.val<index2.val:
cur.next=ListNode(index1.val)
index1=index1.next
else:
cur.next=ListNode(index2.val)
index2=index2.next
cur=cur.next
if (index1):
cur.next=index1
if(index2):
cur.next=index2
return head.next