-
Notifications
You must be signed in to change notification settings - Fork 0
153. Find Minimum in Rotated Sorted Array
Linjie Pan edited this page May 21, 2019
·
1 revision
Whatever how we rotate the array, either the left or the right part will be a sorted subarray:
- If the rightmost element of the left subarray is larger than the rightmost element of the right part, then the pivot point must exist in the right part;
- Otherwise, the pivot point exists in the left part.
public int findMin(int[] nums) {
int begin = 0, end = nums.length - 1;
while( begin < end ) {
int mid = (begin + end) / 2;
if( nums[mid] > nums[end] ) // pivot point exists in the right part
begin = mid + 1;
else // pivot point exists in the left part
end = mid;
}
return nums[begin];
}