题目链接:https://leetcode-cn.com/problems/find-peak-element/
//两种方法:
一:
class Solution {
public:
int findPeakElement(vector<int>& nums) {
int lo = 0;
int hi = nums.length - 1;
while (lo + 1 < hi) {
int mid = lo + (hi - lo) / 2;
if (nums[mid] > nums[mid + 1]) {
hi = mid;
} else {
lo = mid + 1;
}
}
// post process
if (lo < hi && nums[lo] < nums[hi]) {
return hi;
} else {
return lo;
}
};
二:
int start = 0;
int end = nums.length - 1;
while(start!=end) {
int mid = (start + end) /2;