题目链接:
这个题其实很简单,我们定义一个三层的循环,变量i的值从0开始,变量j的值从i+1开始,变量k的值从j+1开始,最内层只要判断nums[k] - nums[j]) == diff && (nums[j] - nums[i]) == diff即可
代码如下:
int arithmeticTriplets(int* nums, int numsSize, int diff){
int count = 0;
for(int i = 0;i < numsSize;i++)
{
for(int j = i+1;j < numsSize;j++)
{
for(int k = j+1;k < numsSize;k++)
{
if((nums[k] - nums[j]) == diff && (nums[j] - nums[i]) == diff)
{
count++;
}
}
}
}
return count;
}