@@ -0,0 +1,1099 @@
+import java.util.ArrayList;%0A%0A/**%0A * http://leetcode.com/onlinejudge#question_113%0A */%0Apublic class PathSumTwo %7B%0A%0A%09public static void main(String%5B%5D args) %7B%0A%0A%09%7D%0A%0A%09public ArrayList%3CArrayList%3CInteger%3E%3E pathSum(TreeNode root, int sum) %7B%0A%09%09ArrayList%3CArrayList%3CInteger%3E%3E results = new ArrayList%3CArrayList%3CInteger%3E%3E();%0A%09%09if (root == null) %7B%0A%09%09%09return results;%0A%09%09%7D else if (root.val == sum && root.left == null && root.right == null) %7B%0A%09%09%09ArrayList%3CInteger%3E result = new ArrayList%3CInteger%3E();%0A%09%09%09result.add(root.val);%0A%09%09%09results.add(result);%0A%09%09%09return results;%0A%09%09%7D else %7B%0A%09%09%09int partialSum = sum - root.val;%0A%09%09%09ArrayList%3CArrayList%3CInteger%3E%3E leftResult = pathSum(root.left, partialSum);%0A%09%09%09if (!leftResult.isEmpty()) %7B%0A%09%09%09%09for (ArrayList%3CInteger%3E result : leftResult) %7B%0A%09%09%09%09%09result.add(0, root.val);%0A%09%09%09%09%7D%0A%09%09%09%09results.addAll(leftResult);%0A%09%09%09%7D%0A%09%09%09ArrayList%3CArrayList%3CInteger%3E%3E rightResult = pathSum(root.right, partialSum);%0A%09%09%09if (!rightResult.isEmpty()) %7B%0A%09%09%09%09for (ArrayList%3CInteger%3E result : rightResult) %7B%0A%09%09%09%09%09result.add(0, root.val);%0A%09%09%09%09%7D%0A%09%09%09%09results.addAll(rightResult);%0A%09%09%09%7D%0A%09%09%09return results;%0A%09%09%7D%0A%09%7D%0A%7D%0A

path sum 2