![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
二分查找
have a good day.
这个作者很懒,什么都没留下…
展开
-
leetcode — 山脉数组的峰顶索引
执行用时:40 ms 内存消耗:14.5 MB class Solution: def peakIndexInMountainArray(self, arr: List[int]) -> int: left = 0 right = len(arr) - 1 while left <= right: mid = left + (right - left) // 2 if arr[mid-1] &原创 2020-09-22 17:23:40 · 138 阅读 · 0 评论 -
leecode — 找到比目标字母大的最小字母(二分查找)
看到题目想到了二分查找的运行时间为O(logn) class Solution: def nextGreatestLetter(self, letters: List[str], target: str) -> str: left = 0 right = len(letters) - 1 while left <= right: mid = left + (right-left) // 2 if le原创 2020-09-22 17:02:42 · 63 阅读 · 0 评论