image_2021-10-16_01-22-40.png
43 KB
#N1534 Count Good Triplets
problem link=>https://leetcode.com/problems/count-good-triplets/
#solution
problem link=>https://leetcode.com/problems/count-good-triplets/
#solution
class Solution {
public int countGoodTriplets(int[] arr, int a, int b, int c) {
int count=0;
for(int i=0; i<arr.length-2; i++){
for(int j=i+1; j<arr.length-1; j++){
if(Math.abs(arr[i]-arr[j])>a) continue;
for(int k=j+1; k<arr.length; k++){
if(Math.abs(arr[j]-arr[k])<=b&&Math.abs(arr[i]-arr[k])<=c)
count ++;
}
}
}
return count;
}
}