leetcode told me:

Runtime Error Message: Line 17: java.lang.ArrayIndexOutOfBoundsException: -1

Last executed input: [1]

Line 17 is if(num[mid] > num[mid-1] && num[mid] > num[mid+1])

but it returns 0 when I run it in eclipse. I can't figure out why.

```
public int findPeakElement(int[] num) {
if(num.length <= 1)
return 0;
return search(num, 0, num.length-1);
}
private int search(int[] num, int low, int high)
{
int mid = (low+high)/2;
if(low == high)
return low;
if(mid == 0 && num[0] > num[1])
return 0;
if(mid == num.length-1 && num[mid] > num[mid-1])
return mid;
if(num[mid] > num[mid-1] && num[mid] > num[mid+1])
return mid;
else if(num[mid] < num[mid-1] && num[mid] > num[mid+1])
return search(num, low, mid);
else
return search(num, mid, high);
}
```