@@ -0,0 +1,2081 @@
+// Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.%0A%0A// An example is the root-to-leaf path 1-%3E2-%3E3 which represents the number 123.%0A%0A// Find the total sum of all root-to-leaf numbers.%0A%0A// For example,%0A%0A//     1%0A//    / %5C%0A//   2   3%0A// The root-to-leaf path 1-%3E2 represents the number 12.%0A// The root-to-leaf path 1-%3E3 represents the number 13.%0A%0A// Return the sum = 12 + 13 = 25.%0A%0A/**%0A * Definition for binary tree%0A * public class TreeNode %7B%0A *     int val;%0A *     TreeNode left;%0A *     TreeNode right;%0A *     TreeNode(int x) %7B val = x; %7D%0A * %7D%0A */%0Apublic class Solution %7B%0A%09public int sumNumbers(TreeNode root) %7B%0A%09%09return dfs(root, 0);%0A%09%7D%0A%0A%09public int dfs(TreeNode node, int sum)%7B%0A%09%09if(node == null) return 0;%0A%0A%09%09sum = sum * 10 + node.val; %0A%0A%09%09if(node.left == null && node.right == null)%7B%0A%09%09%09return sum;%0A%09%09%7D%0A%0A%09%09return dfs(node.left, sum) + dfs(node.right, sum);%0A%09%7D%0A    // public int sumNumbers(TreeNode root) %7B%0A    // %09if(root == null) return 0;%0A%0A    // %09List%3CList%3CInteger%3E%3E list = new ArrayList%3CList%3CInteger%3E%3E();%0A    //     List%3CInteger%3E tempList = new ArrayList%3CInteger%3E();%0A    //     // List%3CInteger%3E result%0A    //     int sum = 0;%0A%0A    //     dfs(list, tempList, root);%0A%0A    //     tempList = new ArrayList%3CInteger%3E();%0A%0A    //     for(List%3CInteger%3E l : list)%7B%0A    //     %09int num = 0;%0A    //     %09for(int i : l)%7B%0A    //     %09%09num += num*10 + i;%0A    //     %09%7D%0A    //     %09tempList.add(num);%0A    //     %7D%0A%0A    //     for(int i : tempList)%7B%0A    //     %09sum += i;%0A    //     %7D%0A%0A    //     return sum;%0A    // %7D%0A%0A    // public void dfs(List%3CList%3CInteger%3E%3E list, List%3CInteger%3E tempList, TreeNode node)%7B%0A    // %09tempList.add(node.val);%0A%0A    // %09if(node.left == null && node.right == null)%7B%0A    // %09%09List%3CInteger%3E match = new ArrayList%3CInteger%3E(tempList);%0A    // %09%09tempList.remove(tempList.size() - 1);%0A    // %09%09list.add(match);%0A    // %09%09return;%0A    // %09%7D%0A%0A    // %09if(node.left != null)%7B%0A    // %09%09dfs(list, tempList, node.left);%0A    // %09%7D%0A%0A    // %09if(node.right != null)%7B%0A    // %09%09dfs(list, tempList, node.right);%0A    // %09%7D%0A    // %7D%0A%7D

add sum root to leaf numbers solution.