Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def mergeTwoLists(self, l1, l2):
- """
- :type l1: ListNode
- :type l2: ListNode
- :rtype: ListNode
- """
- if not l1 or not l2:
- return l1 or l2
- res = ListNode(0)
- head = res
- temp1 = l1
- temp2 = l2
- while temp1 and temp2:
- if temp1.val <= temp2.val:
- head.next = temp1
- temp1 = temp1.next
- else:
- head.next = temp2
- temp2 = temp2.next
- head = head.next
- remain = temp1 or temp2
- head.next = remain
- return res.next
Add Comment
Please, Sign In to add comment