Python 解LeetCode:744. Find Smallest Letter Greater Than Target

思路:二分法,时间复杂度o(logn)

class Solution(object):
def nextGreatestLetter(self, letters, target):
"""
:type letters: List[str]
:type target: str
:rtype: str
"""
left, right = 0, len(letters) - 1
while left <= right:
mid = (left + right) / 2
if letters[mid] <= target:
left = mid + 1
else:
if mid < 1 or (mid >= 1 and letters[mid-1] <= target):
return letters[mid]
right = mid - 1
return letters[0]
上一篇:wget 增加单个文件下载限制大小


下一篇:E/WindowState(643): getStack: Window{33f867f8 u0 Starting com.xxxxxx.ooooo}