mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
40 lines
1.3 KiB
HTML
40 lines
1.3 KiB
HTML
|
<p>给定一个整数数组<meta charset="UTF-8" /> <code>arr</code> ,以及一个整数 <code>target</code> 作为目标值,返回满足 <code>i < j < k</code> 且<meta charset="UTF-8" /> <code>arr[i] + arr[j] + arr[k] == target</code> 的元组 <code>i, j, k</code> 的数量。</p>
|
|||
|
|
|||
|
<p>由于结果会非常大,请返回 <code>10<sup>9</sup> + 7</code> 的模。</p>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>示例 1:</strong></p>
|
|||
|
|
|||
|
<pre>
|
|||
|
<strong>输入:</strong>arr = [1,1,2,2,3,3,4,4,5,5], target = 8
|
|||
|
<strong>输出:</strong>20
|
|||
|
<strong>解释:</strong>
|
|||
|
按值枚举(arr[i], arr[j], arr[k]):
|
|||
|
(1, 2, 5) 出现 8 次;
|
|||
|
(1, 3, 4) 出现 8 次;
|
|||
|
(2, 2, 4) 出现 2 次;
|
|||
|
(2, 3, 3) 出现 2 次。
|
|||
|
</pre>
|
|||
|
|
|||
|
<p><strong>示例 2:</strong></p>
|
|||
|
|
|||
|
<pre>
|
|||
|
<strong>输入:</strong>arr = [1,1,2,2,2,2], target = 5
|
|||
|
<strong>输出:</strong>12
|
|||
|
<strong>解释:</strong>
|
|||
|
arr[i] = 1, arr[j] = arr[k] = 2 出现 12 次:
|
|||
|
我们从 [1,1] 中选择一个 1,有 2 种情况,
|
|||
|
从 [2,2,2,2] 中选出两个 2,有 6 种情况。
|
|||
|
</pre>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>提示:</strong></p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li><code>3 <= arr.length <= 3000</code></li>
|
|||
|
<li><code>0 <= arr[i] <= 100</code></li>
|
|||
|
<li><code>0 <= target <= 300</code></li>
|
|||
|
</ul>
|