class Solution {
public:
int peakIndexInMountainArray(vector<int>& A) {
if (A.size() < 3||A[0]>A[1])return 0;
bool flag = false;
int k = 0;
for (int i = 1; i < A.size()-1; ++i) {
if (A[i] > A[i + 1] && !flag){
k = i;
flag = true;
}
if (A[i] < A[i + 1] && flag)return 0;
}
if (!flag)return 0;
return k;
}
};
852. Peak Index in a Mountain Array
最新推荐文章于 2023-07-25 13:58:18 发布