Skip to content

Commit 21de1af

Browse files
authored
Create find-the-winner-of-an-array-game.py
1 parent 30d4dda commit 21de1af

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def getWinner(self, arr, k):
6+
"""
7+
:type arr: List[int]
8+
:type k: int
9+
:rtype: int
10+
"""
11+
result = arr[0]
12+
count = 0
13+
for i in xrange(1, len(arr)):
14+
if arr[i] > result:
15+
result = arr[i]
16+
count = 0
17+
count += 1
18+
if (count == k):
19+
break
20+
return result

0 commit comments

Comments
 (0)