1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 11:08:15 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/使数组严格递增 [make-array-strictly-increasing].html

42 lines
1.6 KiB
HTML
Raw Normal View History

2022-03-27 20:37:52 +08:00
<p>给你两个整数数组&nbsp;<code>arr1</code><code>arr2</code>,返回使&nbsp;<code>arr1</code>&nbsp;严格递增所需要的最小「操作」数(可能为 0</p>
<p>每一步「操作」中,你可以分别从 <code>arr1</code><code>arr2</code> 中各选出一个索引,分别为&nbsp;<code>i</code>&nbsp;<code>j</code><code>0 &lt;=&nbsp;i &lt; arr1.length</code>&nbsp;&nbsp;<code>0 &lt;= j &lt; arr2.length</code>,然后进行赋值运算&nbsp;<code>arr1[i] = arr2[j]</code></p>
<p>如果无法让&nbsp;<code>arr1</code>&nbsp;严格递增,请返回&nbsp;<code>-1</code></p>
<p>&nbsp;</p>
2023-12-09 18:42:21 +08:00
<p><strong class="example">示例 1</strong></p>
2022-03-27 20:37:52 +08:00
2023-12-09 18:42:21 +08:00
<pre>
<strong>输入:</strong>arr1 = [1,5,3,6,7], arr2 = [1,3,2,4]
2022-03-27 20:37:52 +08:00
<strong>输出:</strong>1
<strong>解释:</strong>用 2 来替换 <code>5之后</code> <code>arr1 = [1, 2, 3, 6, 7]</code>
</pre>
2023-12-09 18:42:21 +08:00
<p><strong class="example">示例 2</strong></p>
2022-03-27 20:37:52 +08:00
2023-12-09 18:42:21 +08:00
<pre>
<strong>输入:</strong>arr1 = [1,5,3,6,7], arr2 = [4,3,1]
2022-03-27 20:37:52 +08:00
<strong>输出:</strong>2
<strong>解释:</strong>用 3 来替换 <code>5然后</code>用 4 来替换 3<code>,得到</code> <code>arr1 = [1, 3, 4, 6, 7]</code>
</pre>
2023-12-09 18:42:21 +08:00
<p><strong class="example">示例&nbsp;3</strong></p>
2022-03-27 20:37:52 +08:00
2023-12-09 18:42:21 +08:00
<pre>
<strong>输入:</strong>arr1 = [1,5,3,6,7], arr2 = [1,6,3,3]
2022-03-27 20:37:52 +08:00
<strong>输出:</strong>-1
<strong>解释:</strong>无法使 <code>arr1 严格递增</code></pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= arr1.length, arr2.length &lt;= 2000</code></li>
<li><code>0 &lt;= arr1[i], arr2[i] &lt;= 10^9</code></li>
</ul>
<p>&nbsp;</p>