# 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; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up