Path Sum II 代码 public class Solution { List<List<Integer>> res = new ArrayList<List<Integer>>(); public List<List<Integer>> pathSum(TreeNode root, int sum) { if(root == null){ return res; } Stack<Integer> path = new Stack<Integer>(); helper(root, sum, path); return res; } public void helper(TreeNode root, int sum, Stack<Integer> path){ path.push(root.val); if(root.left == null && root.right == null){ if(root.val == sum) res.add(new ArrayList<Integer>(path)); } if(root.left != null){ helper(root.left, sum-root.val, path); } if(root.right != null){ helper(root.right, sum-root.val, path); } path.pop(); } }