Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dc3458a commit 2ad6ee4Copy full SHA for 2ad6ee4
1 file changed
Rank/184/1409/solution1.js
@@ -0,0 +1,26 @@
1
+/**
2
+ * https://leetcode-cn.com/problems/queries-on-a-permutation-with-key/
3
+ *
4
+ * 1409. 查询带键的排列
5
6
+ * Medium
7
8
+ * 76ms
9
+ * 41mb
10
11
+ * 时间复杂度 O(n^2)
12
+ * 空间复杂度 O(n)
13
+ */
14
+const processQueries = (queries, m) => {
15
+ const ans = [];
16
+ const list = Array.from({ length: m }, (item, index) => index + 1);
17
+
18
+ for (let i = 0, max = queries.length; i < max; i++) {
19
+ const item = queries[i];
20
+ const index = list.findIndex(el => el === item);
21
+ ans.push(index);
22
+ list.splice(index, 1);
23
+ list.unshift(item);
24
+ }
25
+ return ans;
26
+}
0 commit comments