[LeetCode][python3]0002. Add Two Numbers
Start the Journey
N2I -2020.03.15
- My first solution
class Solution:
def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
h=p=ListNode()
c=0
while True:
if c==0 and l1==None and l2==None:
break
a=b=0
if l1:
a=l1.val
l1=l1.next
if l2:
b=l2.val
l2=l2.next
n=a+b+c
if n>=10:
n-=10
p.next=ListNode(n)
c=1
else:
p.next=ListNode(n)
c=0
p=p.next
return h.next
2. Other solution
(Most of them are in the same logic)