2113. Elements in Array After Removing and Replacing Elements

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

Содержание

LeetCode problem 2113

class Solution:
    def elementInNums(self, nums: List[int], queries: List[List[int]]) -> List[int]:
        n, m = len(nums), len(queries)
        res = [-1] * m
        for j, (t, i) in enumerate(queries):
            t %= 2 * n
            if t < n and i < n - t:
                res[j] = nums[i + t]
            elif t > n and i < t - n:
                res[j] = nums[i]
        return res