```
class Solution(object):
def sumNumbers(self, root):
if not root: return 0
self.res=0
self.cal(root, '')
return self.res
def cal(self, root, temp):
if not root: return
if not root.left and not root.right: self.res+=int(temp+str(root.val))
for node in [root.left, root.right]: self.cal(node, temp+str(root.val))
```