mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
41 lines
1.4 KiB
HTML
41 lines
1.4 KiB
HTML
<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> </p>
|
|
<p><strong>Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> nums = [0,1,4,6,7,10], diff = 3
|
|
<strong>Output:</strong> 2
|
|
<strong>Explanation:</strong>
|
|
(1, 2, 4) is an arithmetic triplet because both 7 - 4 == 3 and 4 - 1 == 3.
|
|
(2, 4, 5) is an arithmetic triplet because both 10 - 7 == 3 and 7 - 4 == 3.
|
|
</pre>
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> nums = [4,5,6,7,8,9], diff = 2
|
|
<strong>Output:</strong> 2
|
|
<strong>Explanation:</strong>
|
|
(0, 2, 4) is an arithmetic triplet because both 8 - 6 == 2 and 6 - 4 == 2.
|
|
(1, 3, 5) is an arithmetic triplet because both 9 - 7 == 2 and 7 - 5 == 2.
|
|
</pre>
|
|
|
|
<p> </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>
|