题
思
二分
代码
class Solution {
public int findMin(int[] nums) {
if (nums.length == 1) {
return nums[0];
}
if (nums[0] < nums[nums.length - 1]) {
return nums[0];
}
int start = 0, end = nums.length - 1;
int mid;
while (start < end) {
mid = (start + end) / 2;
if (nums[mid] > nums[start]) {
start = mid;
} else {
end = mid;
}
}
return nums[start + 1];
}
}