vector<int> shortestToChar(string S, char C) {
    vector<int> V;

    const int N = 10001;
    int AYC[N];
    int countC = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == C)
        {
            AYC[countC] = i;
            countC++;
        }
    }
    for (int i = 0; i < S.size(); i++)
    {
        int min = INT_MAX;
        for (int j = 0; j < countC; j++)
        {
            int dif = abs(i - AYC[j]);
            if (dif < min)
            {
                min = dif;
            }
        }
        V.push_back(min);
    }
    return V;
}

 

posted on 2018-09-27 22:14  Sempron2800+  阅读(84)  评论(0编辑  收藏  举报