Tag:With key

  • Leetcode 1409. Query keyed permutation – Python

    Time:2021-7-27

    1409. Query keyed arrangement Three solutions Solution I violence class Solution: def processQueries(self, queries: List[int], m: int) -> List[int]: m = min(m, max(queries)) p = [i+1 for i in range(m)] ans = [] for x in queries: i = p.index(x) ans.append(i) x = p.pop(i) p.insert(0, x) return ans Solution two deque # from collections import […]