-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path69.py
More file actions
46 lines (36 loc) · 1.16 KB
/
69.py
File metadata and controls
46 lines (36 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def replaceVowel(word: str) -> str:
res = ""
for chr in word.lower():
if chr in ("a", "o", "e", "u", "i"):
res = res + "_"
else:
res = res + chr
return res
class Solution:
def spellchecker(self, wordlist: List[str], queries: List[str]) -> List[str]:
words = set(wordlist)
cap = dict()
vow = dict()
# Go reverse to get the first word
for word in wordlist[::-1]:
# print(word)
cap[word.lower()] = word
vowel_word = replaceVowel(word)
vow[vowel_word] = word
res = []
for word in queries:
if word in words:
res.append(word)
else:
w = cap.get(word.lower(), None)
if w is not None:
# print(f"cap: {word}")
res.append(w)
continue
w = vow.get(replaceVowel(word), None)
if w is not None:
# print(f"vow: {word}")
res.append(w)
continue
res.append("")
return res