1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/使序列递增的最小交换次数 [minimum-swaps-to-make-sequences-increasing].html
2022-03-29 12:43:11 +08:00

45 lines
1.5 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>我们有两个长度相等且不为空的整型数组&nbsp;<code>nums1</code>&nbsp;&nbsp;<code>nums2</code>&nbsp;。在一次操作中,我们可以交换&nbsp;<code>nums1[i]</code>&nbsp;&nbsp;<code>nums2[i]</code>的元素。</p>
<ul>
<li>例如,如果 <code>nums1 = [1,2,3,<u>8</u>]</code> <code>nums2 =[5,6,7,<u>4</u>]</code> ,你可以交换 <code>i = 3</code> 处的元素,得到 <code>nums1 =[1,2,3,4]</code><code>nums2 =[5,6,7,8]</code></li>
</ul>
<p>返回 <em>使 <code>nums1</code><code>nums2</code> <strong>严格递增&nbsp;</strong>所需操作的最小次数</em></p>
<p>数组&nbsp;<code>arr</code>&nbsp;<strong>严格递增</strong>&nbsp;&nbsp;<code>arr[0] &lt; arr[1] &lt; arr[2] &lt; ... &lt; arr[arr.length - 1]</code>&nbsp;</p>
<p><b>注意:</b></p>
<ul>
<li>用例保证可以实现操作。</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong> nums1 = [1,3,5,4], nums2 = [1,2,3,7]
<strong>输出:</strong> 1
<strong>解释: </strong>
交换 A[3] 和 B[3] 后,两个数组如下:
A = [1, 3, 5, 7] B = [1, 2, 3, 4]
两个数组均为严格递增的。</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong> nums1 = [0,3,5,8,9], nums2 = [2,1,4,6,9]
<strong>输出:</strong> 1
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 &lt;= nums1.length &lt;= 10<sup>5</sup></code></li>
<li><code>nums2.length == nums1.length</code></li>
<li><code>0 &lt;= nums1[i], nums2[i] &lt;= 2 * 10<sup>5</sup></code></li>
</ul>