题解 | #旋转数组的最小数字#
旋转数组的最小数字
http://www.nowcoder.com/practice/9f3231a991af4f55b95579b44b7a01ba
-- coding:utf-8 --
class Solution: def minNumberInRotateArray(self, rotateArray): # write code here lIdx = 0 rIdx = len(rotateArray)-1 mid = lIdx
mid = lIdx + (rIdx-lIdx)>>1
while rotateArray[lIdx] >= rotateArray[rIdx]:
mid = lIdx + ((rIdx-lIdx)>>1)
print(lIdx, rIdx, mid)
if mid == lIdx and rIdx - lIdx==1:
return rotateArray[rIdx]
if rotateArray[mid] == rotateArray[rIdx] and rotateArray[mid] == rotateArray[lIdx]:
minNum = rotateArray[lIdx]
for item in range(lIdx+1, rIdx+1, 1):
if rotateArray[item]<minNum:
minNum = rotateArray[item]
return minNum
if rotateArray[mid] >= rotateArray[lIdx]:
lIdx = mid
elif rotateArray[mid] <= rotateArray[rIdx]:
rIdx = mid
return rotateArray[mid]