python代码
# -*- coding:utf-8 -*-
class Solution:
def minNumberInRotateArray(self, rotateArray):
# write code here
if len(rotateArray) == 0:
return 0
else:
minV = rotateArray[0]
for i in rotateArray:
if i <= minV:
minV = i
return minV
对于python而言,即使不是旋转数组,也只能这么做。
对于C++而言,旋转数组意味着按顺序排列,且中间值是最小值,所以应该用二分查找算法做。