mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-09 09:21:40 +08:00
45 lines
2.0 KiB
HTML
45 lines
2.0 KiB
HTML
<p>You are given an integer array <code>order</code> of length <code>n</code> and an integer array <code>friends</code>.</p>
|
|
|
|
<ul>
|
|
<li><code>order</code> contains every integer from 1 to <code>n</code> <strong>exactly once</strong>, representing the IDs of the participants of a race in their <strong>finishing</strong> order.</li>
|
|
<li><code>friends</code> contains the IDs of your friends in the race <strong>sorted</strong> in strictly increasing order. Each ID in friends is guaranteed to appear in the <code>order</code> array.</li>
|
|
</ul>
|
|
|
|
<p>Return an array containing your friends' IDs in their <strong>finishing</strong> order.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">order = [3,1,2,5,4], friends = [1,3,4]</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">[3,1,4]</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>The finishing order is <code>[<u><strong>3</strong></u>, <u><strong>1</strong></u>, 2, 5, <u><strong>4</strong></u>]</code>. Therefore, the finishing order of your friends is <code>[3, 1, 4]</code>.</p>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">order = [1,4,5,3,2], friends = [2,5]</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">[5,2]</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>The finishing order is <code>[1, 4, <u><strong>5</strong></u>, 3, <u><strong>2</strong></u>]</code>. Therefore, the finishing order of your friends is <code>[5, 2]</code>.</p>
|
|
</div>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= n == order.length <= 100</code></li>
|
|
<li><code>order</code> contains every integer from 1 to <code>n</code> exactly once</li>
|
|
<li><code>1 <= friends.length <= min(8, n)</code></li>
|
|
<li><code>1 <= friends[i] <= n</code></li>
|
|
<li><code>friends</code> is strictly increasing</li>
|
|
</ul>
|