题解 | #旋转数组的最小数字#
旋转数组的最小数字
http://www.nowcoder.com/practice/9f3231a991af4f55b95579b44b7a01ba
本题的关键是对于非降序数组的理解以及处理取值相等的情况
class Solution:
def minNumberInRotateArray(self , rotateArray: List[int]) -> int:
# write code here
array_len = len(rotateArray)
left = 0
right = array_len - 1
while left < right:
mid = int((left + right) / 2)
if rotateArray[mid] > rotateArray[right]:
left = mid + 1
elif rotateArray[mid] < rotateArray[right]:
right = mid
elif rotateArray[mid] == rotateArray[right]:
right -= 1
return rotateArray[right]