Skip to content

Commit 2c654bd

Browse files
authored
Create Number of Arithmetic Triplets.java
1 parent f68218e commit 2c654bd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int arithmeticTriplets(int[] nums, int diff) {
3+
int count = 0;
4+
Set<Integer> set = new HashSet<>();
5+
for (int num : nums) {
6+
if (set.contains(num - diff) && set.contains(num - 2 * diff)) {
7+
count++;
8+
}
9+
set.add(num);
10+
}
11+
return count;
12+
}
13+
}

0 commit comments

Comments
 (0)