Count Good Triplets LeetCode solution in Java
1class Solution {2public int countGoodTriplets(int[] arr, int a, int b, int c) {3int total = 0;4for (int i = 0; i < arr.length - 2; i++) {5for (int j = i + 1; j < arr.length - 1; j++) {6for (int k = j + 1; k < arr.length; k++) {7if (helper(arr[i], arr[j]) <= a8&& helper(arr[j], arr[k]) <= b9&& helper(arr[k], arr[i]) <= c) total++;10}11}12}13return total;14}1516private static int helper(int x, int y) {17return Math.abs(x - y);18}19}