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)/下标对中的最大距离 [maximum-distance-between-a-pair-of-values].html
2022-03-29 12:43:11 +08:00

47 lines
2.1 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>非递增</strong> 的整数数组 <code>nums1</code><code>nums2</code> ,数组下标均 <strong>从 0 开始</strong> 计数。</p>
<p>下标对 <code>(i, j)</code><code>0 &lt;= i &lt; nums1.length</code><code>0 &lt;= j &lt; nums2.length</code> 。如果该下标对同时满足 <code>i &lt;= j</code><code>nums1[i] &lt;= nums2[j]</code> ,则称之为 <strong>有效</strong> 下标对,该下标对的 <strong>距离</strong><code>j - i</code> 。​​</p>
<p>返回所有 <strong>有效</strong> 下标对<em> </em><code>(i, j)</code><em> </em>中的 <strong>最大距离</strong> 。如果不存在有效下标对,返回 <code>0</code></p>
<p>一个数组 <code>arr</code> ,如果每个 <code>1 &lt;= i &lt; arr.length</code> 均有 <code>arr[i-1] &gt;= arr[i]</code> 成立,那么该数组是一个 <strong>非递增</strong> 数组。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums1 = [55,30,5,4,2], nums2 = [100,20,10,10,5]
<strong>输出:</strong>2
<strong>解释:</strong>有效下标对是 (0,0), (2,2), (2,3), (2,4), (3,3), (3,4) 和 (4,4) 。
最大距离是 2 ,对应下标对 (2,4) 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums1 = [2,2,2], nums2 = [10,10,1]
<strong>输出:</strong>1
<strong>解释:</strong>有效下标对是 (0,0), (0,1) 和 (1,1) 。
最大距离是 1 ,对应下标对 (0,1) 。</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>nums1 = [30,29,19,5], nums2 = [25,25,25,25,25]
<strong>输出:</strong>2
<strong>解释:</strong>有效下标对是 (2,2), (2,3), (2,4), (3,3) 和 (3,4) 。
最大距离是 2 ,对应下标对 (2,4) 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums1.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums2.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums1[i], nums2[j] &lt;= 10<sup>5</sup></code></li>
<li><code>nums1</code><code>nums2</code> 都是 <strong>非递增</strong> 数组</li>
</ul>