Number of Arithmetic Triplets
class Solution { public: int arithmeticTriplets(vector<int>& nums, int diff) { int triplets=0; int size=nums.size(); for(int i=0;i<size-2;i++) { for(int y=i+1;y<size-1;y++) { for(int z=y+1;z<size;z++) { if(nums[y]-nums[i] == diff && nums[z]-nums[y] == diff) { ++triplets; } } } } return triplets; } };
Leave a Comment