题解 | #旋转排列之找出最矮的牛#
旋转排列之找出最矮的牛
https://www.nowcoder.com/practice/ea91217beb83444aa324b86bfab4a952
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param heights int整型vector
* @return int整型
*/
int findMin(vector<int>& heights) {
// write code here
int left = 0, right = heights.size()-1;
if (heights[0] > heights[right]) return heights[right];
while (left < right) {
int mid = (left + right) >> 1;
if (heights[0] > heights[mid]) {
left = mid+1;
} else {
right = mid;
}
}
return heights[left-1];
}
};

快手成长空间 767人发布