-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ45.js
29 lines (22 loc) · 839 Bytes
/
Q45.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 2367. Number of Arithmetic Triplets
// You are given a 0-indexed, strictly increasing integer array nums and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the following conditions are met:
// i < j < k,
// nums[j] - nums[i] == diff, and
// nums[k] - nums[j] == diff.
// Return the number of unique arithmetic triplets.
var arithmeticTriplets = function(nums, diff) {
let count = 0;
for (let i = 0; i < nums.length; i++) {
for(let j = i+1; j<nums.length; j++) {
for(let k = j+1; k<nums.length;k++) {
if (i<j && j<k && nums[j]-nums[i] === diff && nums[k]-nums[j] === diff) {
count++
}
}
}
}
return count
};
let nums = [4,5,6,7,8,9]
let diff = 2
console.log(arithmeticTriplets(nums,diff));