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)/满足不等式的数对数目 [number-of-pairs-satisfying-inequality].html
2022-10-07 21:03:28 +08:00

42 lines
1.7 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>给你两个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>nums1</code>&nbsp;<code>nums2</code>&nbsp;,两个数组的大小都为&nbsp;<code>n</code>&nbsp;,同时给你一个整数&nbsp;<code>diff</code>&nbsp;,统计满足以下条件的&nbsp;<strong>数对&nbsp;</strong><code>(i, j)</code>&nbsp;</p>
<ul>
<li><code>0 &lt;= i &lt; j &lt;= n - 1</code>&nbsp;<b></b></li>
<li><code>nums1[i] - nums1[j] &lt;= nums2[i] - nums2[j] + diff</code>.</li>
</ul>
<p>请你返回满足条件的 <strong>数对数目</strong>&nbsp;</p>
<p>&nbsp;</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 = 13 - 2 &lt;= 2 - 2 + 1 。因为 i &lt; j 且 1 &lt;= 1 ,这个数对满足条件。
2. i = 0, j = 23 - 5 &lt;= 2 - 1 + 1 。因为 i &lt; j 且 -2 &lt;= 2 ,这个数对满足条件。
3. i = 1, j = 22 - 5 &lt;= 2 - 1 + 1 。因为 i &lt; j 且 -3 &lt;= 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>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == nums1.length == nums2.length</code></li>
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>4</sup> &lt;= nums1[i], nums2[i] &lt;= 10<sup>4</sup></code></li>
<li><code>-10<sup>4</sup> &lt;= diff &lt;= 10<sup>4</sup></code></li>
</ul>