Guest User

Untitled

a guest
Oct 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. # Definition for singly-linked list.
  2. # class ListNode:
  3. # def __init__(self, x):
  4. # self.val = x
  5. # self.next = None
  6.  
  7. class Solution:
  8. def mergeTwoLists(self, l1, l2):
  9. """
  10. :type l1: ListNode
  11. :type l2: ListNode
  12. :rtype: ListNode
  13. """
  14. res = tail = ListNode(0)
  15.  
  16. while l1 and l2:
  17. if l1.val<l2.val:
  18. tail.next, l1 = l1, l1.next
  19. else:
  20. tail.next, l2 = l2, l2.next
  21. tail = tail.next
  22. tail.next = l1 or l2
  23. return res.next
Add Comment
Please, Sign In to add comment