8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 39c78a7 commit 593503fCopy full SHA for 593503f
leetcode/AddTwoNumbers.py
@@ -0,0 +1,35 @@
1
+#-*- coding:utf-8 -*-
2
+'''
3
+Created on 2017年5月12日
4
+
5
+@author: huangjiaxin
6
7
+#Definition for singly-linked list.
8
+class ListNode(object):
9
+ def __init__(self, x):
10
+ self.val = x
11
+ self.next = None
12
13
+class Solution(object):
14
+ def addTwoNumbers(self, l1, l2):
15
+ """
16
+ :type l1: ListNode
17
+ :type l2: ListNode
18
+ :rtype: ListNode
19
20
+ l3 = ListNode(0)
21
+ root = l3
22
+ val = 0
23
+ while l1 or l2 or val:
24
+ tempval = 0
25
+ if l1:
26
+ tempval += l1.val
27
+ l1 = l1.next
28
+ if l2:
29
+ tempval += l2.val
30
+ l2 = l2.next
31
+ val, nowval = divmod(tempval + val, 10)
32
+ tempList = ListNode(nowval)
33
+ l3.next = tempList
34
+ l3 = l3.next
35
+ return root.next
0 commit comments