mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
42 lines
1.6 KiB
HTML
42 lines
1.6 KiB
HTML
<p>给你两个整数数组 <code>arr1</code> 和 <code>arr2</code>,返回使 <code>arr1</code> 严格递增所需要的最小「操作」数(可能为 0)。</p>
|
||
|
||
<p>每一步「操作」中,你可以分别从 <code>arr1</code> 和 <code>arr2</code> 中各选出一个索引,分别为 <code>i</code> 和 <code>j</code>,<code>0 <= i < arr1.length</code> 和 <code>0 <= j < arr2.length</code>,然后进行赋值运算 <code>arr1[i] = arr2[j]</code>。</p>
|
||
|
||
<p>如果无法让 <code>arr1</code> 严格递增,请返回 <code>-1</code>。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong class="example">示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>arr1 = [1,5,3,6,7], arr2 = [1,3,2,4]
|
||
<strong>输出:</strong>1
|
||
<strong>解释:</strong>用 2 来替换 <code>5,之后</code> <code>arr1 = [1, 2, 3, 6, 7]</code>。
|
||
</pre>
|
||
|
||
<p><strong class="example">示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>arr1 = [1,5,3,6,7], arr2 = [4,3,1]
|
||
<strong>输出:</strong>2
|
||
<strong>解释:</strong>用 3 来替换 <code>5,然后</code>用 4 来替换 3<code>,得到</code> <code>arr1 = [1, 3, 4, 6, 7]</code>。
|
||
</pre>
|
||
|
||
<p><strong class="example">示例 3:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>arr1 = [1,5,3,6,7], arr2 = [1,6,3,3]
|
||
<strong>输出:</strong>-1
|
||
<strong>解释:</strong>无法使 <code>arr1 严格递增</code>。</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= arr1.length, arr2.length <= 2000</code></li>
|
||
<li><code>0 <= arr1[i], arr2[i] <= 10^9</code></li>
|
||
</ul>
|
||
|
||
<p> </p>
|