微信圖片_20191220190256.jpg
##### 【解法一:遍歷】####
class Solution:
def minNumberInRotateArray(self, rotateArray):
# write code here
if len(rotateArray)==0:
return 0
if len(rotateArray) == 1:
return rotateArray[0]
else:
for index in range(1, len(rotateArray)):
if rotateArray[index] < rotateArray[index-1]:
return rotateArray[index]
##### 【解法一:二分法】####
class Solution:
def minNumberInRotateArray(self, rotateArray):
# write code here
left = 0
right = len(rotateArray) - 1
while left <= right:
mid = (left + right) >> 1
if rotateArray[mid] > rotateArray[mid+1]:
return rotateArray[mid+1]
if rotateArray[mid] > rotateArray[right]:
left = mid
else:
right = mid