public int peakIndexInMountainArray(int[] arr) {
    int l = 0, r = arr.length - 1;
    while(l < r) {
        int mid = l + (r-l)/2;
        if(arr[mid] < arr[mid+1])
            l = mid + 1;
        else
            r = mid;
    }
    return l;
}
public boolean searchMatrix(int[][] matrix, int target) {
    int m = matrix.length, n = matrix[0].length;
    int l = 0, r = m*n-1;
    while(l <= r) {
        int mid = l + (r-l)/2;
        int val = matrix[mid / n][mid % n];
        if(val == target)
            return true;
        else if(val > target) {
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    return false;
}

darren987469