leetcode-1535-找出数组游戏的赢家
题目描述:
方法一:双指针 O(N) O(1)
class Solution: def getWinner(self, arr: List[int], k: int) -> int: strike = 0 cur, i = 0, 1 while i < len(arr): if arr[i] < arr[cur]: i += 1 strike += 1 if strike == k: return arr[cur] else: cur = i i += 1 strike = 1 if strike == k: return arr[cur] return arr[cur]