Java less wordy,

  • 0
    public class Solution {
        public List<List<Integer>> pathSum(TreeNode root, int sum) {
            List<List<Integer>> l= new ArrayList<>();
            f(root, sum, l, new ArrayList<>());
            return l;
        void f(TreeNode x, int sum, List<List<Integer>> l, List<Integer> ll){
            f(x.left, sum-x.val, l,new ArrayList<>(ll));
            f(x.right, sum-x.val, l, new ArrayList<>(ll));
            if(x.left==null && x.right==null && sum-x.val==0)l.add(ll);

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.