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)/按既定顺序创建目标数组 [create-target-array-in-the-given-order].html
2022-03-29 12:43:11 +08:00

57 lines
1.7 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>给你两个整数数组 <code>nums</code><code>index</code>。你需要按照以下规则创建目标数组:</p>
<ul>
<li>目标数组 <code>target</code> 最初为空。</li>
<li>按从左到右的顺序依次读取 <code>nums[i]</code><code>index[i]</code>,在 <code>target</code> 数组中的下标 <code>index[i]</code> 处插入值 <code>nums[i]</code></li>
<li>重复上一步,直到在 <code>nums</code><code>index</code> 中都没有要读取的元素。</li>
</ul>
<p>请你返回目标数组。</p>
<p>题目保证数字插入位置总是存在。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>nums = [0,1,2,3,4], index = [0,1,2,2,1]
<strong>输出:</strong>[0,4,1,3,2]
<strong>解释:</strong>
nums index target
0 0 [0]
1 1 [0,1]
2 2 [0,1,2]
3 2 [0,1,3,2]
4 1 [0,4,1,3,2]
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>nums = [1,2,3,4,0], index = [0,1,2,3,0]
<strong>输出:</strong>[0,1,2,3,4]
<strong>解释:</strong>
nums index target
1 0 [1]
2 1 [1,2]
3 2 [1,2,3]
4 3 [1,2,3,4]
0 0 [0,1,2,3,4]
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>nums = [1], index = [0]
<strong>输出:</strong>[1]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length, index.length &lt;= 100</code></li>
<li><code>nums.length == index.length</code></li>
<li><code>0 &lt;= nums[i] &lt;= 100</code></li>
<li><code>0 &lt;= index[i] &lt;= i</code></li>
</ul>