1535. Find the Winner of an Array Game

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1535

class Solution:
    def getWinner(self, arr: List[int], k: int) -> int:
        mx = arr[0]
        cnt = 0
        for x in arr[1:]:
            if mx < x:
                mx = x
                cnt = 1
            else:
                cnt += 1
            if cnt == k:
                break
        return mx