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-operations-to-make-a-subsequence].html
2022-03-29 12:43:11 +08:00

33 lines
1.7 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>给你一个数组 <code>target</code> ,包含若干 <strong>互不相同</strong> 的整数,以及另一个整数数组 <code>arr</code> <code>arr</code> <strong>可能</strong> 包含重复元素。</p>
<p>每一次操作中,你可以在 <code>arr</code> 的任意位置插入任一整数。比方说,如果 <code>arr = [1,4,1,2]</code> ,那么你可以在中间添加 <code>3</code> 得到 <code>[1,4,<strong>3</strong>,1,2]</code> 。你可以在数组最开始或最后面添加整数。</p>
<p>请你返回 <strong>最少</strong> 操作次数,使得<em> </em><code>target</code><em> </em>成为 <code>arr</code> 的一个子序列。</p>
<p>一个数组的 <strong>子序列</strong> 指的是删除原数组的某些元素(可能一个元素都不删除),同时不改变其余元素的相对顺序得到的数组。比方说,<code>[2,7,4]</code> 是 <code>[4,<strong>2</strong>,3,<strong>7</strong>,2,1,<strong>4</strong>]</code> 的子序列(加粗元素),但 <code>[2,4,2]</code> 不是子序列。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>target = [5,1,3], <code>arr</code> = [9,4,2,3,4]
<b>输出:</b>2
<b>解释:</b>你可以添加 5 和 1 ,使得 arr 变为 [<strong>5</strong>,9,4,<strong>1</strong>,2,3,4] target 为 arr 的子序列。
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>target = [6,4,8,1,3,2], <code>arr</code> = [4,7,6,2,3,8,6,1]
<b>输出:</b>3
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= target.length, arr.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= target[i], arr[i] &lt;= 10<sup>9</sup></code></li>
<li><code>target</code> 不包含任何重复元素。</li>
</ul>