```
class Solution(object):
def sumNumbers(self, root):
"""
:type root: TreeNode
:rtype: int
"""
if not root:
return 0
self.num = 0
self.helper(root,0)
return self.num
def helper(self,node,sum):
if node.left:
self.helper(node.left,sum*10+node.val)
if node.right:
self.helper(node.right,sum*10+node.val)
if not node.left and not node.right:
self.num += sum*10+node.val
return
```