Number of Arithmetic Triplets

mail@pastecode.io avatar
unknown
c_cpp
4 months ago
542 B
1
Indexable
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