1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/统计好三元组 [count-good-triplets].html
2022-03-29 12:43:11 +08:00

41 lines
1.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个整数数组 <code>arr</code> ,以及 <code>a</code><code>b</code><code>c</code> 三个整数。请你统计其中好三元组的数量。</p>
<p>如果三元组 <code>(arr[i], arr[j], arr[k])</code> 满足下列全部条件,则认为它是一个 <strong>好三元组</strong></p>
<ul>
<li><code>0 &lt;= i &lt; j &lt; k &lt;&nbsp;arr.length</code></li>
<li><code>|arr[i] - arr[j]| &lt;= a</code></li>
<li><code>|arr[j] - arr[k]| &lt;= b</code></li>
<li><code>|arr[i] - arr[k]| &lt;= c</code></li>
</ul>
<p>其中 <code>|x|</code> 表示 <code>x</code> 的绝对值。</p>
<p>返回 <strong>好三元组的数量</strong></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>arr = [3,0,1,1,9,7], a = 7, b = 2, c = 3
<strong>输出:</strong>4
<strong>解释:</strong>一共有 4 个好三元组:[(3,0,1), (3,0,1), (3,1,1), (0,1,1)] 。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>arr = [1,1,2,2,3], a = 0, b = 0, c = 1
<strong>输出:</strong>0
<strong>解释:</strong>不存在满足所有条件的三元组。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 &lt;= arr.length &lt;= 100</code></li>
<li><code>0 &lt;= arr[i] &lt;= 1000</code></li>
<li><code>0 &lt;= a, b, c &lt;= 1000</code></li>
</ul>