> For the complete documentation index, see [llms.txt](https://timmybeeflin.gitbook.io/cracking-leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://timmybeeflin.gitbook.io/cracking-leetcode/dfs-and-bfs/dfs/129.-sum-root-to-leaf-numbers-1.md).

# Copy of 129. Sum Root to Leaf Numbers

<https://leetcode.com/problems/sum-root-to-leaf-numbers/>

trick point:&#x20;

```java
int currentSum = sum*10 + root.val;
```

```java
class Solution {
    public int sumNumbers(TreeNode root) {
        return cal(root, 0);
    }
    private int cal(TreeNode root, int sum) {
        if (root == null) {
            return 0;
        }
        int currentSum = sum*10 + root.val;
        if (root.left == null && root.right == null) {
            return currentSum;
        }
        return cal(root.left, currentSum) + cal(root.right, currentSum);
        
    }
}
```
