@@ -0,0 +1,1278 @@
+// Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / %5C 4 8 / / %5C 11 13 4 / %5C / %5C 7 2 5 1 return %5B %5B5,4,11,2%5D, %5B5,8,4,5%5D %5D%0A%0A%0A%0A// Sum = 22%09%09%09%09%09%0A%0A//%09%09%095 %0A//%09%09   / %5C%0A//%09%09  4   8 %0A//%09%09 /   / %5C %0A//%09%0911  13  4 %0A//%09   / %5C     / %5C %0A//%09  7   2   5   1 %0A%0A%0Apublic class Solution %7B%0A    public List%3CList%3CInteger%3E%3E pathSum(TreeNode root, int sum) %7B%0A    %09List%3CList%3CInteger%3E%3E result = new ArrayList%3CList%3CInteger%3E%3E();%0A        if(root == null)%7B%0A            return result;%0A        %7D%0A%0A        List%3CInteger%3E sols = new ArrayList%3CInteger%3E();%0A%0A        dfs(result, sols, root, sum);%0A%0A        return result;%0A    %7D%0A%0A    public void dfs(List%3CList%3CInteger%3E%3E result, List%3CInteger%3E sols, TreeNode node, int num)%7B%0A        if(node == null) return;%0A%0A        num -= node.val;%0A%0A        if(node.left == null && node.right == null)%7B%0A            if(num == 0)%7B%0A                sols.add(node.val);%0A                result.add(new ArrayList%3CInteger%3E(sols));%0A                sols.remove(sols.size() - 1);%0A            %7D%0A            return;%0A        %7D%0A%0A        sols.add(node.val);%0A        dfs(result, sols, node.left, num);%0A        dfs(result, sols, node.right, num);%0A        sols.remove(sols.size() - 1);%0A    %7D%0A%7D

add path sum ii solution;