题目
代码实现
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
int findPeakElement(vector<int>& nums) {
int len = nums.size();
int left = 0, right = len - 1, mid;
while (left < right) {
mid = left + (right - left) / 2;
if (nums[mid] > nums[mid + 1]) {
right = mid;
}
else {
left = mid + 1;
}
}
return right;
}
};
int main()
{
Solution test;
vector<int> input = { 1,2,1,3,5,6,4 };
int result = test.findPeakElement(input); ;
cout << "result:" << result << endl;
}