mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-04 06:51:41 +08:00
存量题库数据更新
This commit is contained in:
@@ -1,35 +1,38 @@
|
||||
<p>给你一个待查数组 <code>queries</code> ,数组中的元素为 <code>1</code> 到 <code>m</code> 之间的正整数。 请你根据以下规则处理所有待查项 <code>queries[i]</code>(从 <code>i=0</code> 到 <code>i=queries.length-1</code>):</p>
|
||||
<p>给定一个正整数数组 <code>queries</code> ,其取值范围在 <code>1</code> 到 <code>m</code> 之间。 请你根据以下规则按顺序处理所有 <code>queries[i]</code>(从 <code>i=0</code> 到 <code>i=queries.length-1</code>):</p>
|
||||
|
||||
<ul>
|
||||
<li>一开始,排列 <code>P=[1,2,3,...,m]</code>。</li>
|
||||
<li>对于当前的 <code>i</code> ,请你找出待查项 <code>queries[i]</code> 在排列 <code>P</code> 中的位置(<strong>下标从 0 开始</strong>),然后将其从原位置移动到排列 <code>P</code> 的起始位置(即下标为 0 处)。注意, <code>queries[i]</code> 在 <code>P</code> 中的位置就是 <code>queries[i]</code> 的查询结果。</li>
|
||||
<li>首先,你有一个排列 <code>P=[1,2,3,...,m]</code>。</li>
|
||||
<li>对于当前的 <code>i</code> ,找到 <code>queries[i]</code> 在排列 <code>P</code> 中的位置(<b>从 0 开始索引</b>),然后将它移到排列 <code>P</code> 的开头(即下标为 0 处)。注意, <code>queries[i]</code> 的查询结果是 <code>queries[i]</code> 在 <code>P</code> 中移动前的位置。</li>
|
||||
</ul>
|
||||
|
||||
<p>请你以数组形式返回待查数组 <code>queries</code> 的查询结果。</p>
|
||||
<p>返回一个数组,包含从给定 <code>queries</code> 中查询到的结果。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>queries = [3,1,2,1], m = 5
|
||||
<pre>
|
||||
<strong>输入:</strong>queries = [3,1,2,1], m = 5
|
||||
<strong>输出:</strong>[2,1,2,1]
|
||||
<strong>解释:</strong>待查数组 queries 处理如下:
|
||||
对于 i=0: queries[i]=3, P=[1,2,3,4,5], 3 在 P 中的位置是 <strong>2</strong>,接着我们把 3 移动到 P 的起始位置,得到 P=[3,1,2,4,5] 。
|
||||
对于 i=1: queries[i]=1, P=[3,1,2,4,5], 1 在 P 中的位置是 <strong>1</strong>,接着我们把 1 移动到 P 的起始位置,得到 P=[1,3,2,4,5] 。
|
||||
对于 i=2: queries[i]=2, P=[1,3,2,4,5], 2 在 P 中的位置是 <strong>2</strong>,接着我们把 2 移动到 P 的起始位置,得到 P=[2,1,3,4,5] 。
|
||||
对于 i=3: queries[i]=1, P=[2,1,3,4,5], 1 在 P 中的位置是 <strong>1</strong>,接着我们把 1 移动到 P 的起始位置,得到 P=[1,2,3,4,5] 。
|
||||
因此,返回的结果数组为 [2,1,2,1] 。
|
||||
<strong>解释:处理</strong> queries 的过程如下:
|
||||
对于 i=0: queries[i]=3, P=[1,2,3,4,5], 3 在 P 中的位置是 <strong>2</strong>,然后我们把 3 移动到 P 的开头,得到 P=[3,1,2,4,5] 。
|
||||
对于 i=1: queries[i]=1, P=[3,1,2,4,5], 1 在 P 中的位置是 <strong>1</strong>,然后我们把 1 移动到 P 的开头,得到 P=[1,3,2,4,5] 。
|
||||
对于 i=2: queries[i]=2, P=[1,3,2,4,5], 2 在 P 中的位置是 <strong>2</strong>,然后我们把 2 移动到 P 的开头,得到 P=[2,1,3,4,5] 。
|
||||
对于 i=3: queries[i]=1, P=[2,1,3,4,5], 1 在 P 中的位置是 <strong>1</strong>,然后我们把 1 移动到 P 的开头,得到 P=[1,2,3,4,5] 。
|
||||
因此,包含结果的数组为 [2,1,2,1] 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>queries = [4,1,2,2], m = 4
|
||||
<pre>
|
||||
<strong>输入:</strong>queries = [4,1,2,2], m = 4
|
||||
<strong>输出:</strong>[3,1,2,0]
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>queries = [7,5,5,8,3], m = 8
|
||||
<pre>
|
||||
<strong>输入:</strong>queries = [7,5,5,8,3], m = 8
|
||||
<strong>输出:</strong>[6,5,0,7,5]
|
||||
</pre>
|
||||
|
||||
|
Reference in New Issue
Block a user