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>给你一个下标从 <strong>0</strong> 开始、<strong>严格递增</strong> 的整数数组 <code>nums</code> 和一个正整数 <code>diff</code> 。如果满足下述全部条件,则三元组 <code>(i, j, k)</code> 就是一个 <strong>算术三元组</strong> :</p>
|
||
|
||
<ul>
|
||
<li><code>i < j < k</code> ,</li>
|
||
<li><code>nums[j] - nums[i] == diff</code> 且</li>
|
||
<li><code>nums[k] - nums[j] == diff</code></li>
|
||
</ul>
|
||
|
||
<p>返回不同 <strong>算术三元组</strong> 的数目<em>。</em></p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>nums = [0,1,4,6,7,10], diff = 3
|
||
<strong>输出:</strong>2
|
||
<strong>解释:</strong>
|
||
(1, 2, 4) 是算术三元组:7 - 4 == 3 且 4 - 1 == 3 。
|
||
(2, 4, 5) 是算术三元组:10 - 7 == 3 且 7 - 4 == 3 。
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>nums = [4,5,6,7,8,9], diff = 2
|
||
<strong>输出:</strong>2
|
||
<strong>解释:</strong>
|
||
(0, 2, 4) 是算术三元组:8 - 6 == 2 且 6 - 4 == 2 。
|
||
(1, 3, 5) 是算术三元组:9 - 7 == 2 且 7 - 5 == 2 。
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</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> <strong>严格</strong> 递增</li>
|
||
</ul>
|