-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcode153.cpp
More file actions
27 lines (26 loc) · 769 Bytes
/
leetcode153.cpp
File metadata and controls
27 lines (26 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// beats over 61% of submission
class Solution {
public:
int findMin(vector<int>& nums) {
if(nums.size() == 1) return nums[0];
int start = 0, end = nums.size() - 1, mid;
while(start < end) {
mid = start + ((end - start) >> 1);
if(nums[mid] > nums[end]) start = mid + 1;
else end = mid;
}
return nums[start];
}
};
// beats over 94% of submission
int findMin(vector<int>& nums) {
if(nums.size() == 1) return nums[0];
int start = 0, end = nums.size() - 1, mid;
while(start < end) {
if(nums[start] < nums[end]) break;
mid = start + ((end - start) >> 1);
if(nums[mid] > nums[end]) start = mid + 1;
else end = mid;
}
return nums[start];
}