// Source : https://oj.leetcode.com/problems/find-peak-element/
// Inspired by : http://www.jiuzhang.com/solutions/find-peak-element/
// Author : Lei Cao
// Date : 2014-10-05
package findPeakElement;
public class findPeakElement {
public int findPeakElement(int[] nums) {
if (nums.length == 0) {
return Integer.MIN_VALUE;
}
int start = 0;
int end = nums.length - 1;
while (start + 1 < end) {
int mid = start + (end - start) / 2;
if (nums[mid - 1] < nums[mid] && nums[mid] > nums[mid + 1]) {
return mid;
} else if (nums[mid - 1] < nums[mid]) {
start = mid;
} else {
end = mid;
}
}
if (nums[start] > nums[end]) {
return start;
} else {
return end;
}
}
}