利用mid区分左右段
class Solution {
public int findMin(int[] nums) {
if (nums.length == 0) {
return -1;
}
int left = 0, right = nums.length - 1, mid = 0;
while (left < right) {
mid = left + (right - left) / 2;
if (nums[mid] >= nums[left] && nums[mid] > nums[right]) { // 左段
left = mid + 1;
} else if (nums[mid] <= nums[right] && nums[mid] < nums[left]) { // 右段
right = mid; // 最小值可能是mid, 所以不再减1
} else { // 单调
right = mid - 1;
}
}
return nums[left];
}
}