class Solution { public int sumNumbers(TreeNode root) { return sumNumber("", root); } private int sumNumber(String str, TreeNode node){ if(node==null) return 0; str+=Integer.toString(node.val); if(node.left==null&&node.right==null) return Integer.parseInt(str); int res=0; if(node.left!=null) res+=sumNumber(str, node.left); if(node.right!=null) res+=sumNumber(str, node.right); return res; } }