Open rocksc30 opened 1 year ago
class Solution {
public:
string decodeMessage(string key, string message) {
unordered_map<char,char> dic;
int len = key.size();
int cnt = 0;
for(int i = 0; i < len ;i++)
{
if( key[i]!=' ' && dic.find(key[i]) == dic.end() )
{
dic[key[i]] = 'a' + cnt++;
}
}
string ret = "";
for(int i = 0;i < message.length();i++)
{
if(message[i] == ' ')
ret.push_back(message[i]);
else
ret.push_back(dic[message[i]]);
}
return ret;
}
};