Sample answer

class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length;
        int n = matrix[0].length;

        int left = 0;
        int right = n * m - 1;

        while (left <= right) {
            int mid = left + (right-left)/2;

            int val = matrix[mid/n][mid%n];

            if (val == target) return true;
            if (val < target) left = mid + 1;
            if (val > target) right = mid - 1;
        }

        return false;
    }
}

My own attempt

class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {
        int[] row=matrix[0];
        int left=0;
        int right=matrix[0].length-1;

        for (int[] r:matrix) {
            if (r[right] >= target) {
                row = r;
                break;
            }
        }

        while (left <= right) {
            int mid = left + (right-left)/2;
            int midVal = row[mid];
            //System.out.println(midVal);

            if (midVal == target) return true;
            if (midVal > target) right = mid-1;
            if (midVal < target) left = mid + 1;
        }

        return false;
    }
}