852. Peak Index in a Mountain Array
Input: [0,1,0]
Output: 1Input: [0,2,1,0]
Output: 1解题要点:
class Solution {
public int peakIndexInMountainArray(int[] A) {
int max = -1;
for(int i = 0; i < A.length - 1; i++){
if(max < A[i]) max = A[i];
if(max > A[i + 1]) return i;
}
return 0;
}
}Last updated