哈哈哈我都不知道这道题在干嘛
class Solution {
public int peakIndexInMountainArray(int[] A) {
int i=0;
int len=A.length;
while(i<len-1){
if(A[i]>A[i+1]) return i;
i++;
}
return i;
}
}
写个二分吧
class Solution {
public int peakIndexInMountainArray(int[] A) {
int l=0,r=A.length-1;
while(l<r){
int mid = (l+r)/2;
if(A[mid]>A[mid-1] && A[mid]>A[mid+1]) return mid;
if(A[mid]>A[mid-1]) l = mid;
else r = mid;
}
return l;
}
}
挺没意思的一道题~