## 小旋锋 的博客

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8

# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
"""
:type l1: ListNode
:type l2: ListNode
:rtype: ListNode
"""
p = 0
result = None
current = None
while True:
addValue = l1.val + l2.val + p
p = 0

p = 1

if result == None:
result = node
current = node
else:
current.next = node
current = node

l1 = l1.next
l2 = l2.next

if l1 == None or l2 == None:
break

if l1 == None and l2 == None:
pass
elif l1 == None or l2 == None:
rest = None
if l1 == None:
rest = l2
else :
rest = l1

while True:
p = 0

p = 1

current.next = node
current = node

rest = rest.next
if rest == None:
break

if p == 0:
return result
else:
node = ListNode(p)
current.next = node
return result

2016-04-04 17:58:23

2015-07-02 16:14:53

2015-08-18 20:56:43

#### 【LeetCode】2. Add Two Numbers 解题报告

2016-10-24 19:46:34

#### [LeetCode] 002. Add Two Numbers (Medium) (C++/Java/Python)

2015-02-27 12:43:08

2017-06-04 14:55:04

2016-04-11 09:48:50

2016-09-18 21:49:47

#### The only legal comparisons are between two numbers, two strings, or two dates

2017-12-17 16:41:25

#### 【LeetCode with Python】 Add Two Numbers

2014-06-27 18:11:19