fork download
  1. class ListNode:
  2. def __init__(self, val=0, next=None):
  3. self.val = val
  4. self.next = next
  5.  
  6. l1 = [1,3,5]
  7. l2 = [4,2,6]
  8.  
  9. def sum_lists(l1, l2):
  10.  
  11. dummy = ListNode(0)
  12. current = dummy
  13.  
  14. while l1 or l2:
  15. current.next = ListNode(l1.val + l2.val)
  16. current = current.next
  17.  
  18. if l1:
  19. l1 = l1.next
  20. if l2:
  21. l2 = l2.next
  22.  
  23. return dummy.next
Success #stdin #stdout 0.11s 14140KB
stdin
Standard input is empty
stdout
Standard output is empty