public int findPeakElement(int[] nums) {
        int low = 0;
        int high = nums.length - 1;
        int middle = 0;
        while (low <= high) {
            middle = (low + high)/2;
            int before = Integer.MIN_VALUE;
            if (middle > 0) {
                before = nums[middle - 1];
            }
            int after = Integer.MIN_VALUE;
            if (middle < nums.length - 1) {
                after = nums[middle + 1];
            }
            if (nums[middle] > before && nums[middle] > after) {
                return middle;
            } else if (before > after) {
                high = middle - 1;
            } else {
                low = middle + 1;
            }
        }
        return middle;
    }
@author Tushar Roy
Date 01/17/2107
A peak element is an element that is greater than its neighbors. Find index of peak element in the array.

Space complexity is O(1)
Time complexity is O(n)

https://leetcode.com/problems/find-peak-element/
src/com/interview/binarysearch/PeakElement.java