---
# System prepended metadata

title: 2367. Number of Arithmetic Triplets
tags: [Leetcode, Easy]

---

# 2367. Number of Arithmetic Triplets
###### tags: `Leetcode` `Easy`
Link: https://leetcode.com/problems/number-of-arithmetic-triplets/description/
## 思路
对于每一个数先检查num-diff和num-diff-diff在不在set里面 如果在的话ans+1
再把num放进set里面
## Code
```java=
class Solution {
    public int arithmeticTriplets(int[] nums, int diff) {
        Set<Integer> set = new HashSet<>();
        int ans = 0;
        for(int num:nums){
            if(set.contains(num-diff) && set.contains(num-2*diff)) ans++;
            set.add(num);
        }
        return ans;
    }
}
```