题解 | #旋转数组的最小数字#
旋转数组的最小数字
https://www.nowcoder.com/practice/9f3231a991af4f55b95579b44b7a01ba
class Solution { public: int minNumberInRotateArray(vector<int> rotateArray) { //计算数组长度 int len = rotateArray.size() - 1; //遍历数组 for(int i=0;i<len;i++){ //如果数组元素不是全部相等,旋转后的数组的最小值的索引值一定是最大值的索引值+1 if(rotateArray[i]>rotateArray[i+1]) return rotateArray[i+1]; } //当数组元素值全部相等时 return rotateArray[0]; } };