public boolean searchMatrix(int[][] matrix, int target) {//passed after consulting answer
        if (matrix.length < 1) {
            return false;
        }
        int bottom = 0;
        int top = matrix.length*matrix[0].length-1;
        while (bottom <= top) {
            int mid = (bottom + top) / 2,
                midX = mid / matrix[0].length,
                midY = mid % matrix[0].length;
            if (matrix[midX][midY] == target) {
                return true;
            }
            else if (matrix[midX][midY] > target) {
                top = mid - 1;
            }
            else {
                bottom = mid + 1;
            }
        }
        return false;
    }