You are viewing a single comment's thread. Return to all comments →
Java
public static int beautifulTriplets(int d, List<Integer> arr) { int nTriplets = 0; for (int i = 0; i < arr.size(); i++) { int j = arr.subList(i + 1, arr.size()).indexOf(arr.get(i) + d); nTriplets += (j != -1 && arr.subList(j + 1, arr.size()).contains(arr.get(i) + 2 * d)) ? 1 : 0; } return nTriplets; }
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Triplets
You are viewing a single comment's thread. Return to all comments →
Java