class Solution {
public:
int peakIndexInMountainArray(vector<int>& A) {
int temp = 0;
for(int i = 0;i<A.size();i++)
{
if (A[i]>A[i+1])
{
temp = i;
break;
}
}
return temp;
}
};
判断开始减小的转折点,break跳出
class Solution {
public:
int peakIndexInMountainArray(vector<int>& A) {
int i = 0;
while(A[i] < A[i + 1])
i++;
return i;
}
};
二分查找