Skip to content

Commit

Permalink
Time: 531 ms (61.41%), Space: 29.5 MB (94.02%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
hovanhoa committed Nov 5, 2023
1 parent 8b924c4 commit b2e39cf
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution:
def getWinner(self, arr: List[int], k: int) -> int:
if k == 1:
return max(arr[0], arr[1])
if k >= len(arr):
return max(arr)

current_winner = arr[0]
consecutive_wins = 0

for i in range(1, len(arr)):
if current_winner > arr[i]:
consecutive_wins += 1
else:
current_winner = arr[i]
consecutive_wins = 1

if consecutive_wins == k:
return current_winner

return current_winner

0 comments on commit b2e39cf

Please sign in to comment.