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);
}
};