3
vector<string> spellchecker(vector<string> &wordlist, vector<string> &queries) {4
unordered_map<string, vector<int>> umap;6
// step 1: add info in umap;7
for (int curr = 0; curr < wordlist.size(); curr++) {9
umap[wordlist[curr]].push_back({curr});10
// notice that the lowercase may appear;12
// case 2: add lowercase;13
string tmp = wordlist[curr];14
transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);16
if (umap.find(tmp) == umap.end() && tmp != wordlist[curr]) umap[tmp].push_back({curr});18
// case 3: add vowel errors;19
// convert aeiou to _;20
for (int c_index = 0; c_index < tmp.size(); c_index++) {21
char c = tmp[c_index];22
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') tmp[c_index] = '_';25
if (umap.find(tmp) == umap.end()) umap[tmp].push_back({curr});28
// step 2: convert queries;29
for (int curr = 0; curr < queries.size(); curr++) {30
string tmp = queries[curr];31
transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);33
// case 1: check same;34
if (umap.find(queries[curr]) != umap.end()) {35
queries[curr] = (umap[queries[curr]].size() == 1) ? wordlist[umap[queries[curr]][0]]36
: wordlist[umap[queries[curr]][1]];40
// case 2: check lowercase;41
if (umap.find(tmp) != umap.end() && tmp != queries[curr]) {42
queries[curr] = wordlist[umap[tmp][0]];46
// case 3: check vowel errors;47
// convert aeiou to _;48
for (int c_index = 0; c_index < tmp.size(); c_index++) {49
char c = tmp[c_index];50
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') tmp[c_index] = '_';53
if (umap.find(tmp) != umap.end()) {54
queries[curr] = wordlist[umap[tmp][0]];66
// 1. When the query exactly matches a word in the wordlist (case-sensitive),67
// you should return the same word back.68
// 2. When the query matches a word up to capitlization, you should return the69
// first such match in the wordlist.70
// 3. When the query matches a word up to vowel errors, you should return the71
// first such match in the wordlist.72
// 4. If the query has no matches in the wordlist, you should return the empty