153. 寻找旋转排序数组中的最小值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution:
def findMin(self, nums: List[int]) -> int:
# 1、复原方法
left = 0
right = len(nums)-1
# def restore(nums):
# while nums[left] > nums[right]:
# nums.insert(0,nums.pop())
# return nums
# return restore(nums)[0]
# 2、二分法
def search_II(left,right):
while left<right:
mid = (left+right)>>1
if nums[mid]<nums[right]: # 一定不在右侧
right = mid
else:
left = mid+1
return left
return nums[search_II(left,right)]