1.题目:
2.解析:
代码:
方法一:以最后一个元素为参照物
int left = 0, right = nums.length-1;
int n = nums.length-1;
while(left < right) {
int mid = left+(right-left)/2;
if(nums[mid] > nums[n]) left = mid+1;
else right = mid;
}
return nums[left];
//方法二:以第一个元素为参照物
int left = 0, right = nums.length-1;
int min = 0;
while(left < right) {
int mid = left+(right-left)/2;
if(nums[mid] < nums[0]) right = mid;
else left = mid+1;
}
min = nums[left];
return min > nums[0] ? nums[0] : min;