题解 | #寻找峰值#
寻找峰值
http://www.nowcoder.com/practice/1af528f68adc4c20bf5d1456eddb080a
二分查找思路
public int solve (int[] a) { // write code here if(a== null || a.length == 0) return 0; int ans = Integer.MIN_VALUE; for(int i = 0;i < a.length-1;++i){ int low = i,high = a.length-1;//要留出两个数字,所以low最大是a.length-2 while(low < high){ int mid = low + (high-low)/2; if(a[mid] < a[mid+1]){ low = mid+1; }else{ high = mid; } } ans = Math.max(ans,low); } return ans; }