
原题链接
class Solution {
List<List<Integer>> res = new ArrayList<>();
LinkedList<Integer> path = new LinkedList<>();
public List<List<Integer>> pathSum(TreeNode root, int target) {
if(root == null) return res;
recur(root, target, 0);
return res;
}
public void recur(TreeNode root, int target, int sum){
if(root == null) return;
path.offerLast(root.val);
sum += root.val;
if(root.left == null && root.right == null && sum == target){
res.add(new LinkedList<>(path));
}
recur(root.left, target, sum);
recur(root.right, target, sum);
path.pollLast();
sum -= root.val;
}
}