1652. Defuse the Bomb

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

Содержание

LeetCode problem 1652

class Solution:
    def decrypt(self, code: List[int], k: int) -> List[int]:
        n = len(code)
        res = [0] * n
        if k == 0:
            return res
        s = list(accumulate(code + code, initial=0))
        for i in range(n):
            if k > 0:
                res[i] = s[i + k + 1] - s[i + 1]
            else:
                res[i] = s[i + n] - s[i + k + n]
        return res