Queries on a Permutation With Key
给一组queries, 和一个数字m, 求在数组[1,m]执行queries后的数组.
这题仔细观察题目即可. 没啥好优化的…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
class Solution { public int[] processQueries(int[] queries, int m) { List<Integer> list = new LinkedList<>(); for(int i = 1; i <= m; i++){ list.add(i); } int[] res = new int[queries.length]; for(int i = 0; i < queries.length; i++) { res[i] = list.indexOf(queries[i]); list.add(0,list.remove(res[i])); } return res; } } |