public class Solution {
public int findPeakElement(int[] num) {
int length = num.length;
int left = 0;
int right = length1;
int a=0;
while(left<=right){ //左右开工找peak，直到两个element重合为止
if(left==right){
a = left;
break;
}
int mid = (left+right)/2;
if(num[mid]<num[mid+1]){
left = mid+1;
}else{
right = mid;
}
}
return a;
}
}
My binary search java solution


Sorry. I think I gave a wrong example. Let's see
{5, 4, 3, 2, 1, 9, 7}. In your solution, The first mid will be 2. Since it is bigger than 1, we will only look left side after then. And obviously, there is no peak number on left side.
So, as long as we build a descend order number on left side and make it pass middle point. and make a peak number somewhere on right side. This solution will fail.