【LeetCode】2325. 解密消息

class Solution {
public:
    string decodeMessage(string key, string message) {
    string letters = "abcdefghijklmnopqrstuvwxyz";
    int index = 0;
    for (int i = 0; i < key.length(); )
    {
        if (key[i] == ' ')
        {
            key.erase(i, 1); 
            continue;
        }
        else
        {
            for (int j = i + 1; j < key.length(); )
            {
                if (key[j] == key[i]) key.erase(j, 1);
                else j++;
            }
            i++;
        }
    }

    for (int i = 0; i < message.length(); i++)
    {
        if('a' <= message[i] && message[i] <= 'z')
        {
            index = key.find_first_of(message[i],0);
            message[i] = letters[index];
        }
    }
    return message;
    }
};
posted @ 2023-02-01 10:39  小超不挑食  阅读(14)  评论(0编辑  收藏  举报