package leetcode;

/**
 * https://leetcode.com/problems/number-of-good-leaf-nodes-pairs/
 */
public class Problem1530 {
    public static 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;
        }
    }

    public int countPairs(TreeNode root, int distance) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1530 prob = new Problem1530();
    }
}

@@ -12,16 +12,108 @@
 tcode;%0A%0A
+import java.util.List;%0Aimport java.util.stream.Collectors;%0Aimport java.util.stream.Stream;%0A%0A
 /**%0A * h
@@ -639,15 +639,81 @@
     
-// TODO
+IntRef answer = new IntRef();%0A        countPairs(root, distance, answer);
 %0A   
@@ -724,17 +724,26 @@
  return 
-0
+answer.val
 ;%0A    %7D%0A
@@ -752,91 +752,1042 @@
    p
-ublic static void main(String%5B%5D args) %7B%0A        Problem1530 prob = new Problem1530(
+rivate static class IntRef %7B%0A        private int val;%0A    %7D%0A%0A    private static List%3CInteger%3E countPairs(TreeNode root, int distance, IntRef answer) %7B%0A        if (root == null) %7B%0A            return List.of();%0A        %7D%0A        if (root.left == null && root.right == null) %7B%0A            return List.of(1);%0A        %7D%0A        List%3CInteger%3E left = countPairs(root.left, distance, answer);%0A        List%3CInteger%3E right = countPairs(root.right, distance, answer);%0A        if (!left.isEmpty() && !right.isEmpty()) %7B%0A            answer.val += left.stream()%0A                .flatMap(e1 -%3E right.stream().filter(e2 -%3E e1 + e2 %3C= distance))%0A                .count();%0A            return Stream.concat(%0A                left.stream().map(e -%3E e + 1),%0A                right.stream().map(e -%3E e + 1))%0A                .collect(Collectors.toList());%0A        %7D%0A        if (!left.isEmpty()) %7B%0A            return left.stream().map(e -%3E e + 1).collect(Collectors.toList());%0A        %7D%0A        return right.stream().map(e -%3E e + 1).collect(Collectors.toList()
 );%0A 

Solve problem 1530