public boolean searchMatrix(int[][] matrix, int target) {
        //find row
        if (target < matrix[0][0]) {
            return false;
        }

        int startRow = 0;
        int endRow = matrix.length - 1;
        while (startRow <= endRow) {
            int midRow = (startRow + endRow) / 2;
            if (target == matrix[midRow][0]) {
                return true;
            } else if (target < matrix[midRow][0]) {
                endRow = midRow - 1;
            } else {
                startRow = midRow + 1;
            }
        }
        int currentRow = startRow;
        if (startRow == matrix.length || matrix[currentRow][0] > target) {
            currentRow -= 1;
        }
        //currentRow = (startRow == matrix.length ? startRow - 1 : startRow);
//        System.out.println(currentRow);
        int startCol = 0;
        int endCol = matrix[currentRow].length-1;
        while (startCol <= endCol) {
            int midCol = (startCol + endCol) / 2;
            if (target < matrix[currentRow][midCol]) {
                endCol = midCol-1;
            } else if (target > matrix[currentRow][midCol]) {
                startCol = midCol + 1;
            } else {
                return true;
            }
        }

        return false;

    }