-
Notifications
You must be signed in to change notification settings - Fork 284
Expand file tree
/
Copy pathAC_simulation_n.py
More file actions
42 lines (32 loc) · 864 Bytes
/
Copy pathAC_simulation_n.py
File metadata and controls
42 lines (32 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Author: illuz <iilluzen[at]gmail.com>
# File: AC_simulation_n.py
# Create Date: 2015-02-02 20:46:14
# Descripton: simulation
# Definition for singly-linked list.
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
# @return a ListNode
def addTwoNumbers(self, l1, l2):
ret = ListNode(0)
cur = ret
sum = 0
while True:
if l1 != None:
sum += l1.val
l1 = l1.next
if l2 != None:
sum += l2.val
l2 = l2.next
cur.val = sum % 10
sum /= 10
if l1 != None or l2 != None or sum != 0:
cur.next = ListNode(0)
cur = cur.next
else:
break
return ret
# debug
s = Solution()