题解 | #旋转数组的最小数字#
旋转数组的最小数字
http://www.nowcoder.com/practice/9f3231a991af4f55b95579b44b7a01ba
很无语 蚌埠住了
太菜了自己 一直想着中间的数和它下一个比较,然后相等的情况一直卡着,不是内存超了就是时间超了。
太笨了 加油吧
class Solution {
public:
int minNumberInRotateArray(vector<int> rotateArray) {
if (rotateArray.size() == 0)
return 0;
int left = 0;
int right = rotateArray.size()-1;
while (left != right){
int half = (left + right)/2;
if (rotateArray[half]>rotateArray[right]){
left = half+1;
}
else if (rotateArray[half]<rotateArray[half+1]){
right = half;
}
else {
right--;
}
}
return rotateArray[left];
}
};
查看1道真题和解析