-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
34 lines (28 loc) · 726 Bytes
/
main.cpp
File metadata and controls
34 lines (28 loc) · 726 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
28
29
30
31
32
33
34
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
int findMin(vector<int>& nums)
{
int left = 0;
int right = (int)nums.size() - 1;
int minimum = INT_MAX;
while (left <= right)
{
if (nums[left] < nums[right]) // array is already sorted
return min(minimum, nums[left]);
int mid = left + (right - left) / 2;
minimum = min(minimum, nums[mid]);
if (nums[mid] >= nums[left])
left = mid + 1; // go right when left is sorted
else
right = mid - 1; // go left when right is sorted
}
return minimum;
}
};
int main()
{
return 0;
}