/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { * this.val = val; * this.left = left; * this.right = right; * } * } */ classSolution{
public List<List<Integer>> pathSum(TreeNode root, int sum) { List<List<Integer>> result = new ArrayList<List<Integer>>(); List<Integer> currPath = new LinkedList(); pathSum(root, sum, currPath, result); return result; }
privatevoidpathSum(TreeNode root, int sum, List<Integer> currPath, List<List<Integer>> result){ if (root == null) { return; }