package interview;
/*
* 数组元素先升后降找出最大值
*/
public class FirstAESCLastDESC {
public static void main(String[] args) {
int[] arrays = {1,2,5,9,5,4};
System.out.println(arrays[searchMax(arrays)]);
}
public static int searchMax(int[] arrays) {
int len = arrays.length;
int begin = 0;
int end=len-1;
int mid = (len-begin)/2;
while(mid>0&&mid<len-1) {
if(arrays[mid] > arrays[mid+1]&& arrays[mid]>arrays[mid-1]) {
return mid;
}else if(arrays[mid]<arrays[mid+1]) {
begin = mid+1;
mid = (end-begin)/2;
}else {
end = mid-1;
mid = (end-begin)/2;
}
}
return -1;
}
}