Skip to content

Commit a2af62b

Browse files
authored
Create slowest-key.py
1 parent 8f11b7e commit a2af62b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Python/slowest-key.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
import collections
5+
6+
7+
class Solution(object):
8+
def slowestKey(self, releaseTimes, keysPressed):
9+
"""
10+
:type releaseTimes: List[int]
11+
:type keysPressed: str
12+
:rtype: str
13+
"""
14+
result, lookup = 'a', collections.Counter()
15+
for i, c in enumerate(keysPressed):
16+
lookup[c] = max(lookup[c], releaseTimes[i]-(releaseTimes[i-1] if i > 0 else 0))
17+
if lookup[c] > lookup[result] or lookup[c] == lookup[result] and c > result:
18+
result = c
19+
return result

0 commit comments

Comments
 (0)