二分查找
好香-
华中科技大学|计算机专业研究生
展开
-
力扣题278
try1×总结:当代码中需要用到2个或多个变量时,要考虑到数组中只有1个元素的情况class Solution(object): def firstBadVersion(self, n): """ :type n: int :rtype: int """ l = 0 r = n-1 while l <= r: mid =(l+r)>&g...原创 2022-05-23 21:40:12 · 179 阅读 · 0 评论 -
力扣题367
解try1 ×class Solution(object): def isPerfectSquare(self, num): """ :type num: int :rtype: bool """ if sqrt(num) * sqrt(num) == num: return True else: return False分析原因:可能因为..原创 2022-05-21 16:16:58 · 115 阅读 · 0 评论 -
力扣题852
解:try1class Solution(object): def peakIndexInMountainArray(self, arr): """ :type arr: List[int] :rtype: int """ l = 0 r = len(arr) - 1 while l <= r: mid = l + (r - l)//2 ..原创 2022-05-19 10:48:53 · 92 阅读 · 0 评论 -
力扣题35
解:常规解法要注意边界值的判断,比如比列表中所有值都大、比列表中所有值都小class Solution(object): def searchInsert(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ l = 0 r = len(nums) - 1 ..原创 2022-05-19 09:50:59 · 259 阅读 · 0 评论