class Solution {
public:
int arithmeticTriplets(vector<int>& nums, int diff) {
int n=nums.size();
set<int> s(nums.begin(),nums.end());
int ans=0;
for(int i=0;i<n;i++)
{
if(s.find(nums[i]-diff)!=s.end() && s.find(nums[i]-2*diff)!=s.end())
{
ans++;
}
}
return ans;
}
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter