MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / Solution

Class Solution

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

Source from the content-addressed store, hash-verified

50# self.right = None
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

no outgoing calls

Tested by

no test coverage detected