```
public class Solution {
int ans = 0;
int sum=0;
public int sumNumbers(TreeNode root) {
SumUp(root);
return ans;
}
void SumUp(TreeNode t){
if(t==null)return;
sum = sum*10+t.val;
if(t.left==null && t.right==null){
ans+=sum;
sum = sum/10;
return;
}
else{
SumUp(t.left);
SumUp(t.right);
}
sum=sum/10;
}
}
```