mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
42 lines
1.7 KiB
HTML
42 lines
1.7 KiB
HTML
|
<p>给你两个下标从 <strong>0</strong> 开始的整数数组 <code>nums1</code> 和 <code>nums2</code> ,两个数组的大小都为 <code>n</code> ,同时给你一个整数 <code>diff</code> ,统计满足以下条件的 <strong>数对 </strong><code>(i, j)</code> :</p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li><code>0 <= i < j <= n - 1</code> <b>且</b></li>
|
|||
|
<li><code>nums1[i] - nums1[j] <= nums2[i] - nums2[j] + diff</code>.</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
<p>请你返回满足条件的 <strong>数对数目</strong> 。</p>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>示例 1:</strong></p>
|
|||
|
|
|||
|
<pre><b>输入:</b>nums1 = [3,2,5], nums2 = [2,2,1], diff = 1
|
|||
|
<b>输出:</b>3
|
|||
|
<strong>解释:</strong>
|
|||
|
总共有 3 个满足条件的数对:
|
|||
|
1. i = 0, j = 1:3 - 2 <= 2 - 2 + 1 。因为 i < j 且 1 <= 1 ,这个数对满足条件。
|
|||
|
2. i = 0, j = 2:3 - 5 <= 2 - 1 + 1 。因为 i < j 且 -2 <= 2 ,这个数对满足条件。
|
|||
|
3. i = 1, j = 2:2 - 5 <= 2 - 1 + 1 。因为 i < j 且 -3 <= 2 ,这个数对满足条件。
|
|||
|
所以,我们返回 3 。
|
|||
|
</pre>
|
|||
|
|
|||
|
<p><strong>示例 2:</strong></p>
|
|||
|
|
|||
|
<pre><b>输入:</b>nums1 = [3,-1], nums2 = [-2,2], diff = -1
|
|||
|
<b>输出:</b>0
|
|||
|
<strong>解释:</strong>
|
|||
|
没有满足条件的任何数对,所以我们返回 0 。
|
|||
|
</pre>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>提示:</strong></p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li><code>n == nums1.length == nums2.length</code></li>
|
|||
|
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
|||
|
<li><code>-10<sup>4</sup> <= nums1[i], nums2[i] <= 10<sup>4</sup></code></li>
|
|||
|
<li><code>-10<sup>4</sup> <= diff <= 10<sup>4</sup></code></li>
|
|||
|
</ul>
|