MCPcopy Create free account
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / addTwoNumbers

Method addTwoNumbers

leetcode/2. Add Two Numbers.py:12–26  ·  view source on GitHub ↗
(self, l1, l2)

Source from the content-addressed store, hash-verified

10
11class Solution(object):
12 def addTwoNumbers(self, l1, l2):
13 pNode = ListNode(0)
14 pHead = pNode
15 val = 0
16 while l1 or l2 or val:
17 if l1:
18 val += l1.val
19 l1 = l1.next
20 if l2:
21 val += l2.val
22 l2 = l2.next
23 pNode.next = ListNode(val % 10)
24 val /= 10
25 pNode = pNode.next
26 return pHead.next

Callers

nothing calls this directly

Calls 1

ListNodeClass · 0.70

Tested by

no test coverage detected