@@ -0,0 +1,1534 @@
+/***%0A * Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.%0A *%0A * For example:%0A * Given the below binary tree and sum = 22,%0A *               5%0A *              / %5C%0A *             4   8%0A *            /   / %5C%0A *           11  13  4%0A *          /  %5C    / %5C%0A *         7    2  5   1%0A * return%0A * %5B%0A *    %5B5,4,11,2%5D,%0A *    %5B5,8,4,5%5D%0A * %5D%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 */%0Aimport java.util.ArrayList;%0Apublic class Solution %7B%0A    public ArrayList%3CArrayList%3CInteger%3E%3E pathSum(TreeNode root, int sum) %7B%0A        ArrayList%3CArrayList%3CInteger%3E%3E ret = new ArrayList%3CArrayList%3CInteger%3E%3E();%0A        ArrayList%3CInteger%3E path = new ArrayList%3CInteger%3E();%0A        findPath(path, ret, root, sum);%0A        return ret;%0A    %7D%0A%0A    private void findPath(ArrayList%3CInteger%3E path, ArrayList%3CArrayList%3CInteger%3E%3E ret, TreeNode root, int sum) %7B%0A        if (root == null) %0A            return;%0A        if (root.left == null && root.right == null) %7B%0A            if (root.val == sum) %7B%0A            ArrayList%3CInteger%3E newpath = new ArrayList%3CInteger%3E(path);%0A            newpath.add(root.val);%0A            ret.add(newpath);%0A            return;%0A            %7D else%0A                return;%0A        %7D%0A        path.add(root.val);%0A        findPath(path, ret, root.left, sum - root.val);%0A        findPath(path, ret, root.right, sum - root.val);%0A        path.remove(path.size() - 1);%0A    %7D%0A%7D%0A

add PathSumII.java