1. 문제
2. 나의 풀이
class ListNode(object):
def __init__(self, val=0, next=None):
self.val = val
self.next = next
class Solution(object):
def addTwoNumbers(self, l1, l2):
"""
:type l1: ListNode
:type l2: ListNode
:rtype: ListNode
"""
node1 = l1
node2 = l2
carry = 0
head = ListNode(0)
tail = head
while node1 or node2:
v1 = node1.val if node1 is not None else 0
v2 = node2.val if node2 is not None else 0
current_sum = v1 + v2 + carry
carry = current_sum /10
current_sum = current_sum % 10
tail.next = ListNode(current_sum)
tail = tail.next
if node1:
node1 = node1.next
if node2:
node2 = node2.next
if carry:
tail.next = ListNode(1)
return head.next
3. 남의 풀이