Find Minimum in Rotated Sorted Array My Submissions Question
Total Accepted: 67103 Total Submissions: 195803 Difficulty: Medium
Suppose a sorted array is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
Find the minimum element.
You may assume no duplicate exists in the array.
Subscribe to see which companies asked this question
class Solution {
public:
int findMin(vector<int>& nums) {
int len = nums.size();
int l = 0;
int r = len - 1;
int mid;
while(l < r - 1){
mid = l + (r - l) / 2;
if(nums[mid] > nums[r]){
l = mid + 1;
}
else if(nums[mid] < nums[r]){
r = mid;
}
}
return nums[r] > nums[l] ? nums[l] : nums[r];
}
};
我今天是咋了? 又是一次AC。。。吃了几个橘子对大脑提升有这么快嘛