MCPcopy
hub / github.com/HuberTRoy/leetCode / sumNumbers

Method sumNumbers

Tree/SumRootToLeafNumbers.py:53–74  ·  view source on GitHub ↗

:type root: TreeNode :rtype: int

(self, root)

Source from the content-addressed store, hash-verified

51
52class Solution(object):
53 def sumNumbers(self, root):
54 """
55 :type root: TreeNode
56 :rtype: int
57 """
58
59 result = []
60 if not root:
61 return 0
62
63 def helper(root, string):
64 if not root.left and not root.right:
65 result.append(int(string+str(root.val)))
66 return
67
68 if root.left:
69 helper(root.left, string+str(root.val))
70
71 if root.right:
72 helper(root.right, string+str(root.val))
73 helper(root, '')
74 return sum(result)

Callers

nothing calls this directly

Calls 1

helperFunction · 0.50

Tested by

no test coverage detected