1
class Solution {
2
public String[] spellchecker(String[] wordlist, String[] queries) {
3
String[] ans = new String[queries.length];
4
Map<String, String>[] map = new HashMap[3];
5
Arrays.setAll(map, o -> new HashMap<>());
6
String pattern = "[aeiou]";
7

8
for (String w : wordlist) {
9
String lo = w.toLowerCase();
10
map[0].put(w, "");
11
map[1].putIfAbsent(lo, w);
12
map[2].putIfAbsent(lo.replaceAll(pattern, "."), map[1].getOrDefault(w, w));
13
}
14

15
int i = 0;
16
for (String q : queries) {
17
String lo = q.toLowerCase();
18
String re = lo.replaceAll(pattern, ".");
19
if (map[0].containsKey(q)) {
20
ans[i] = q;
21
} else if (map[1].containsKey(lo)) {
22
ans[i] = map[1].get(lo);
23
} else if (map[2].containsKey(re)) {
24
ans[i] = map[2].get(re);
25
} else {
26
ans[i] = "";
27
}
28
i++;
29
}
30

31
return ans;
32
}
33
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0