package Depth_first_Search;
public class SumNumbers_129 {
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) {
val = x;
}
}
int sum;
int total;
public int sumNumbers(TreeNode root) {
recur(root);
return total;
}
private void recur(TreeNode root) {
if(root!=null) {
sum=sum*10+root.val;
if(root.left==null&&root.right==null) {
total+=sum;
}
recur(root.left);
recur(root.right);
sum=sum/10;
}
}
}