-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path153.cpp
More file actions
23 lines (23 loc) · 713 Bytes
/
Copy path153.cpp
File metadata and controls
23 lines (23 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
// Runtime: 4 ms, faster than 89.79% of C++ online submissions for Find
// Minimum in Rotated Sorted Array. Memory Usage: 8.8 MB, less than 29.27% of
// C++ online submissions for Find Minimum in Rotated Sorted Array.
public:
int findMin(vector<int> &nums) {
int minVal = 0x7fffffff;
function<void(int, int)> helper = [&](int low, int high) {
if (low > high)
return;
if (nums[low] <= nums[high])
minVal = min(minVal, nums[low]);
else {
int mid = (high + low) / 2;
helper(low, mid - 1);
helper(mid + 1, high);
minVal = min(minVal, nums[mid]);
}
};
helper(0, nums.size() - 1);
return minVal;
}
};