Find Minimum in Rotated Sorted Array
class Solution {
public int findMin(int[] nums) {
if(nums == null || nums.length == 0){
return -1;
}
int s = 0, e = nums.length - 1, target = nums[nums.length - 1];
while(s + 1 < e){
int m = s + (e - s)/2;
//first <= target
if(nums[m] <= target){
e = m;
}else{
s = m;
}
}
if(nums[s] <= target)
return nums[s];
else
return nums[e];
}
}Last updated