标签:amp return else public mount c++ 序列 solution leetcode
class Solution {
public:
int peakIndexInMountainArray(vector<int>& A) {
int res=0;
for(int i=0;i<A.size();i++){
if(A[i] > A[res]){
res=i;
}
}
return res;
}
};
class Solution {
public:
int rec(vector<int>& A, int left, int right){
int mid = (left + right) / 2;
if(mid == 0 || mid == A.size()-2){
if(A[mid] > A[mid+1]){
return mid;
}
else{
return mid+1;
}
}
else{
if(A[mid] > A[mid-1] && A[mid] > A[mid+1]){
return mid;
}
else if(A[mid] > A[mid-1]){
return rec(A, mid, right);
}
else if(A[mid] < A[mid-1]){
return rec(A, left, mid-1);
}
}
}
int peakIndexInMountainArray(vector<int>& A) {
return rec(A, 0, A.size()-1);
}
};
leetcode852 C++ 20ms 找最高峰 序列先增后减
标签:amp return else public mount c++ 序列 solution leetcode
原文地址:https://www.cnblogs.com/theodoric008/p/9456493.html