Created
April 3, 2020 16:19
-
-
Save gjlmotea/1fcadcb0fe28d2930f8e8901021bbfc0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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