-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path744.py
32 lines (28 loc) · 1.15 KB
/
744.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
__________________________________________________________________________________________________
sample 108 ms submission
class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
if target >= letters[-1]:
return letters[0]
left = 0
right = len(letters) - 1
while left + 1 < right:
mid = (left + right) // 2
if letters[mid] <= target:
left = mid
else:
right = mid
if letters[left] > target:
return letters[left]
else:
return letters[right]
__________________________________________________________________________________________________
sample 13120 kb submission
class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
from bisect import bisect_right as b_index
ln_l = len(letters)
i = b_index(letters, target)
if i == ln_l: return letters[0]
else: return letters[i]
__________________________________________________________________________________________________