154. Find Minimum in Rotated Sorted Array II
# Hard
Same as #81.
Solution 1:
consider the edge case: 1 element
skip repeated element at the beginning and end
find the pivot
get result under 2 situations
Solution 2:
remove same element from end
find the pivot
// Java O(logN) solusion
class Solution {
public int findMin(int[] nums) {
int start = 0, end = nums.length - 1;
while(end > 0) {
if(nums[end] != nums[start])
break;
end --;
}
while(start < end) {
int mid = start + (end - start)/2;
if(nums[mid] > nums[end])
start = mid + 1;
else
end = mid;
}
return nums[start];
}
}
Last updated
Was this helpful?