Skip to content

Commit c170bff

Browse files
committed
Time: 7 ms (32.51%), Space: 17.9 MB (57.59%) - LeetHub
1 parent 14e7bb0 commit c170bff

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

0002-add-two-numbers/0002-add-two-numbers.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class Solution:
77
def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:
88
result = ListNode()
9-
cur = result
9+
curr = result
1010
carry = 0
1111

1212
while l1 or l2 or carry:
@@ -16,12 +16,10 @@ def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optio
1616
l1 = l1.next
1717
if l2:
1818
v2 = l2.val
19-
l2 = l2.next
20-
val = v1+v2+carry
21-
carry = val //10
22-
cur.next = ListNode(val%10)
23-
cur = cur.next
19+
l2= l2.next
20+
21+
curr.next = ListNode((v1 + v2 + carry) % 10)
22+
carry = (v1 + v2 + carry) // 10
23+
curr = curr.next
2424

25-
return result.next
26-
27-
25+
return result.next

0 commit comments

Comments
 (0)