-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path154.cpp
More file actions
40 lines (37 loc) · 976 Bytes
/
154.cpp
File metadata and controls
40 lines (37 loc) · 976 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
//
// 154.cpp
// LeetCode
//
// Created by 张佐玮 on 15/6/17.
// Copyright (c) 2015年 JarvisZhang. All rights reserved.
//
// Title: Find Minimum in Rotated Sorted Array II
//
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
int findMin(vector<int>& nums) {
if (nums.empty()) {
return INT_MIN;
}
int start = 0, end = (int) nums.size(), minimum = nums[0];
while (start < end) {
int middle = start + (end - start) / 2;
if (nums[start] < nums[middle]) {
minimum = min(minimum, nums[start]);
start = middle + 1;
}
else if (nums[start] > nums[middle]) {
minimum = min(minimum, nums[middle]);
end = middle;
}
else {
minimum = min(minimum, nums[middle]);
start++;
}
}
return minimum;
}
};