public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length, n = matrix[0].length;
        for (int i = 0; i < m; ++i) {
            int begin = 0, end = n - 1;
            while (begin <= end) {
                int mid = begin + (end - begin) / 2;
                int val = matrix[i][mid];
                if (val == target) {
                    return true;
                } else if (val < target) {
                    begin = mid + 1;
                } else
                    end = mid - 1;
            }
        }
        return false;
    }