class Solution { public List
> pathSum(TreeNode root, int sum) { List
> res=new ArrayList
>(); pathSum(root, sum, new ArrayList (), res); return res; } private void pathSum(TreeNode node, int sum, List list, List
> res){ if(node==null) return; list.add(node.val); if(node.left==null&&node.right==null) { if(node.val==sum) res.add(new ArrayList (list)); } else { if(node.left!=null) pathSum(node.left, sum-node.val, list, res); if(node.right!=null) pathSum(node.right, sum-node.val, list, res); } list.remove(list.size()-1); }}