153 Find Minimum in Rotated Sorted Array
具体思路可以参照33题里面寻找
rotate_index
函数部分。
Java
class Solution {
public int find_rotate_index(int[] nums, int left, int right){
if(nums[left] < nums[right]){
return 0;
}
while(left <= right){
int pivot = left + (right - left)/2;
if (nums[pivot] > nums[pivot + 1])
return pivot + 1;
else
{
if(nums[pivot] < nums[left])
right = pivot - 1;
else
left = pivot + 1;
}
}
return 0;
}
public int findMin(int[] nums) {
if (nums.length == 1)
return nums[0];
return nums[this.find_rotate_index(nums, 0, nums.length - 1)];
}
}