MCPcopy Create free account
hub / github.com/careercup/ctci / addListsFwd2Helper

Function addListsFwd2Helper

python/Chapter 2/Question2_5.py:54–62  ·  view source on GitHub ↗
(p1, p2)

Source from the content-addressed store, hash-verified

52
53# Helper function for recursive adding lists
54def addListsFwd2Helper(p1, p2):
55 if (p1 == None) and (p2 == None):
56 sumandcarry = [None,0] # a python list stores sum node and carry
57 return sumandcarry
58 sumandcarry = addListsFwd2Helper(p1.next, p2.next)
59 val = p1.value + p2.value + sumandcarry[1]
60 dig_node = insertBefore(sumandcarry[0], val%10)
61 carry = val/10
62 return [dig_node, carry]
63
64
65# Helper function to insert node in the front of a linked list

Callers 1

addLists_fwd_2Function · 0.85

Calls 1

insertBeforeFunction · 0.85

Tested by

no test coverage detected