Skip to content

Instantly share code, notes, and snippets.

@gjlmotea
Created April 3, 2020 16:19
Show Gist options
  • Save gjlmotea/1fcadcb0fe28d2930f8e8901021bbfc0 to your computer and use it in GitHub Desktop.
Save gjlmotea/1fcadcb0fe28d2930f8e8901021bbfc0 to your computer and use it in GitHub Desktop.
class Solution:
def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
carry = 0
l3 = ListNode
head = l3
while True:
if l1 == None and l2 == None and carry == 0:
break
sum = 0
sum = sum + carry
if l1 != None:
sum = sum + l1.val
l1 = l1.next
if l2 != None:
sum = sum + l2.val
l2 = l2.next
if(sum > 9):
carry = 1
sum = sum - 10
else:
carry = 0
l3.next = ListNode(sum)
l3 = l3.next
return head.next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment