public int findPeakElement(int[] nums) {
        if (nums == null) return -1;
        int low = 0, high = nums.length - 1;
        while (low <= high) {
            int mid = low + (high - low) / 2;
            /*
             * Compare middle element with its neighbors (if neighbors exists)
             * Same as:
             * if ((mid == 0 && mid == nums.length - 1) ||
             *     (mid == 0 && nums[mid] > nums[mid + 1]) ||
             *     (mid == nums.length - 1 && nums[mid] > nums[mid - 1]) ||
             *     (mid >= 1 && nums[mid] > nums[mid - 1] && mid <= nums.length - 2 && nums[mid] > nums[mid + 1])) return mid;
             */
            if ((mid == 0 || nums[mid] > nums[mid - 1]) && (mid == nums.length - 1 || nums[mid] > nums[mid + 1])) {
                return mid;
            }
            if (mid >= 1 && nums[mid - 1] > nums[mid]) {
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }
        return -1;
    }