【Question】
Suppose a sorted array is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7
might become 4 5 6 7 0 1 2
).
Find the minimum element.
You may assume no duplicate exists in the array.
找到值大小变化的点,如果没有返回第一个数
class Solution {
public:
int findMin(vector<int>& nums) {
int len = nums.size();
int i=0;
while(i<len-1)
{
if(nums[i]>nums[i+1])
return nums[i+1];
i++;
}
return nums[0];
}
};