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)/找到两个数组的前缀公共数组 [find-the-prefix-common-array-of-two-arrays].html
2023-05-03 20:22:43 +08:00

39 lines
1.9 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>给你两个下标从 <strong>0</strong>&nbsp;开始长度为 <code>n</code>&nbsp;的整数排列&nbsp;<code>A</code>&nbsp;<code>B</code>&nbsp;</p>
<p><code>A</code>&nbsp;&nbsp;<code>B</code>&nbsp;<strong>前缀公共数组</strong>&nbsp;定义为数组&nbsp;<code>C</code>&nbsp;,其中&nbsp;<code>C[i]</code>&nbsp;是数组&nbsp;<code>A</code>&nbsp;<code>B</code>&nbsp;到下标为&nbsp;<code>i</code>&nbsp;之前公共元素的数目。</p>
<p>请你返回 <code>A</code>&nbsp;<code>B</code>&nbsp;<strong>前缀公共数组</strong>&nbsp;</p>
<p>如果一个长度为 <code>n</code>&nbsp;的数组包含 <code>1</code>&nbsp;<code>n</code>&nbsp;的元素恰好一次,我们称这个数组是一个长度为 <code>n</code>&nbsp;<strong>排列</strong>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>A = [1,3,2,4], B = [3,1,2,4]
<b>输出:</b>[0,2,3,4]
<b>解释:</b>i = 0没有公共元素所以 C[0] = 0 。
i = 11 和 3 是两个数组的前缀公共元素,所以 C[1] = 2 。
i = 212 和 3 是两个数组的前缀公共元素,所以 C[2] = 3 。
i = 3123 和 4 是两个数组的前缀公共元素,所以 C[3] = 4 。
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>A = [2,3,1], B = [3,1,2]
<b>输出:</b>[0,1,3]
<b>解释:</b>i = 0没有公共元素所以 C[0] = 0 。
i = 1只有 3 是公共元素,所以 C[1] = 1 。
i = 212 和 3 是两个数组的前缀公共元素,所以 C[2] = 3 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= A.length == B.length == n &lt;= 50</code></li>
<li><code>1 &lt;= A[i], B[i] &lt;= n</code></li>
<li>题目保证&nbsp;<code>A</code>&nbsp;&nbsp;<code>B</code>&nbsp;两个数组都是&nbsp;<code>n</code>&nbsp;个元素的排列。</li>
</ul>