forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0153.cpp
32 lines (32 loc) · 749 Bytes
/
0153.cpp
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
#include <iostream>
#include <vector>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
int findMin(vector<int>& nums)
{
int low = 0, high = nums.size() - 1;
while (low <= high)
{
int mid = (high - low)/2 + low;
if (nums[low] <= nums[mid])
{
if (nums[mid] <= nums[high]) return nums[low];
else low = mid + 1;
}
else
{
if (nums[mid] <= nums[high]) high = mid;
}
}
return -1;
}
};
int main()
{
vector<int> nums = {0, -2};
cout << Solution().findMin(nums) << endl;
return 0;
}