Merge two sorted (ascending) linked lists and return it as a new sorted list. The new sorted list should be made by splicing together the nodes of the two lists and sorted in ascending order.
Example
Given 1->3->8->11->15->null, 2->null , return 1->2->3->8->11->15->null.
"""Definition of ListNodeclass ListNode(object): def __init__(self, val, next=None): self.val = val self.next = next"""classSolution:""" @param two ListNodes @return a ListNode """defmergeTwoLists(self,l1,l2):# write your code hereifl1==Noneandl2==None:returnNoneifl1==Noneandl2!=None:returnl2ifl1!=Noneandl2==None:returnl1# Dummy Noderesult=ListNode(-1,None)head=resultwhilel1!=Noneandl2!=None:ifl1.val<=l2.val:head.next=l1l1=l1.nextelse:head.next=l2l2=l2.nexthead=head.next# l1 or l2 is not donewhilel1!=None:head.next=l1l1=l1.nexthead=head.nextwhilel2!=None:head.next=l2l2=l2.nexthead=head.nextreturnresult.next