-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathsolve.cpp
More file actions
41 lines (41 loc) · 744 Bytes
/
solve.cpp
File metadata and controls
41 lines (41 loc) · 744 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
35
36
37
38
39
40
41
#include <vector>
#include <climits>
#include <cstdio>
#include <cstdlib>
using namespace std;
class Solution {
public:
int findMin(vector<int> &nums) {
int n = nums.size();
if (n == 0)
return INT_MIN;
int s = 0, t = n - 1;
while (s < t) {
if (nums[s] < nums[t])
return nums[s];
int mid = (s + t) >> 1;
if (nums[mid] > nums[t]) {
s = mid + 1;
} else if (nums[mid] < nums[t]) {
t = mid;
} else {
t--;
}
}
return nums[s];
}
};
int main(int argc, char **argv)
{
int a[20];
int n;
Solution solution;
while(scanf("%d", &n) != EOF) {
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
}
vector<int> v(a, a + n);
printf("%d\n", solution.findMin(v));
}
return 0;
}