1806. Minimum Number of Operations to Reinitialize a Permutation

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1806

class Solution:
    def reinitializePermutation(self, n: int) -> int:
        res, i = 0, 1
        while 1:
            res += 1
            if i < n >> 1:
                i <<= 1
            else:
                i = (i - (n >> 1)) << 1 | 1
            if i == 1:
                return res