:type root: TreeNode :rtype: int
(self, root)
| 51 | |
| 52 | class 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) |