Class Solution
java.lang.Object
g2301_2400.s2367_number_of_arithmetic_triplets.Solution
2367 - Number of Arithmetic Triplets.<p>Easy</p>
<p>You are given a <strong>0-indexed</strong> , <strong>strictly increasing</strong> integer array <code>nums</code> and a positive integer <code>diff</code>. A triplet <code>(i, j, k)</code> is an <strong>arithmetic triplet</strong> if the following conditions are met:</p>
<ul>
<li><code>i < j < k</code>,</li>
<li><code>nums[j] - nums[i] == diff</code>, and</li>
<li><code>nums[k] - nums[j] == diff</code>.</li>
</ul>
<p>Return <em>the number of unique <strong>arithmetic triplets</strong>.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [0,1,4,6,7,10], diff = 3</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong></p>
<p>(1, 2, 4) is an arithmetic triplet because both 7 - 4 == 3 and 4 - 1 == 3.</p>
<p>(2, 4, 5) is an arithmetic triplet because both 10 - 7 == 3 and 7 - 4 == 3.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [4,5,6,7,8,9], diff = 2</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong></p>
<p>(0, 2, 4) is an arithmetic triplet because both 8 - 6 == 2 and 6 - 4 == 2.</p>
<p>(1, 3, 5) is an arithmetic triplet because both 9 - 7 == 2 and 7 - 5 == 2.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 <= nums.length <= 200</code></li>
<li><code>0 <= nums[i] <= 200</code></li>
<li><code>1 <= diff <= 50</code></li>
<li><code>nums</code> is <strong>strictly</strong> increasing.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
arithmeticTriplets
public int arithmeticTriplets(int[] nums, int diff)
-