2202. Maximize the Topmost Element After K Moves

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

Содержание

LeetCode problem 2202

class Solution:
    def maximumTop(self, nums: List[int], k: int) -> int:
        if k == 0:
            return nums[0]
        n = len(nums)
        if n == 1:
            if k % 2:
                return -1
            return nums[0]
        res = max(nums[: k - 1], default=-1)
        if k < n:
            res = max(res, nums[k])
        return res