package leetcode;

/**
 * https://leetcode.com/problems/count-special-quadruplets/
 */
public class Problem1995 {
    public int countQuadruplets(int[] nums) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1995 prob = new Problem1995();
        System.out.println(prob.countQuadruplets(new int[]{1,2,3,6})); // 1
        System.out.println(prob.countQuadruplets(new int[]{3,3,6,4,5})); // 0
        System.out.println(prob.countQuadruplets(new int[]{1,1,1,3,5})); // 4
    }
}

@@ -12,16 +12,116 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -265,363 +265,777 @@
     
-// TODO%0A        return 0;
+Map%3CInteger, List%3CInteger%3E%3E map = new HashMap%3C%3E();%0A        for (int i = 0; i %3C nums.length; i++) %7B
 %0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1995 prob = new Problem1995();%0A        System.out.println(prob.countQuadruplets(new int%5B%5D%7B1,2,3,6%7D)); // 1%0A        System.out.println(prob.countQuadruplets(new int%5B%5D%7B3,3,6,4,5%7D)); // 0%0A        System.out.println(prob.countQuadruplets(new int%5B%5D%7B1,1,1,3,5%7D)); // 4
+    if (!map.containsKey(nums%5Bi%5D)) %7B%0A                map.put(nums%5Bi%5D, new ArrayList%3C%3E());%0A            %7D%0A            map.get(nums%5Bi%5D).add(i);%0A        %7D%0A        int answer = 0;%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            for (int j = i + 1; j %3C nums.length; j++) %7B%0A                for (int k = j + 1; k %3C nums.length; k++) %7B%0A                    int sum = nums%5Bi%5D + nums%5Bj%5D + nums%5Bk%5D;%0A                    for (int index : map.getOrDefault(sum, List.of())) %7B%0A                        if (k %3C index) %7B%0A                            answer++;%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1995