My LeetCode grinding. Trying to do a problem a day.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617
  1. class Solution:
  2. def processQueries(self, queries, m):
  3. perm = []
  4. result = []
  5. for i in range(1, m + 1):
  6. perm.append(i)
  7. for q in queries:
  8. pos = perm.index(q)
  9. result.append(pos)
  10. perm = [q] + perm[0:pos] + perm[pos + 1:]
  11. return result
  12. s = Solution()
  13. print("Expected: [2, 1, 2, 1]")
  14. print("Got:", s.processQueries([3,1,2,1], 5))