-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path966.py
More file actions
41 lines (37 loc) · 1.23 KB
/
Copy path966.py
File metadata and controls
41 lines (37 loc) · 1.23 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
class Solution:
def spellchecker(self, wordlist, queries):
"""
:type wordlist: List[str]
:type queries: List[str]
:rtype: List[str]
"""
standardDict = set()
lowerCaseDict = {}
vowelDict = {}
ret = []
for i in range(0, len(wordlist)):
word = wordlist[i]
standardDict.add(word)
word = word.lower()
if word not in lowerCaseDict:
lowerCaseDict[word] = i
word = self.ReplacedStr(word)
if word not in vowelDict:
vowelDict[word] = i
for i in range(0, len(queries)):
if queries[i] in standardDict:
ret.append(queries[i])
elif queries[i].lower() in lowerCaseDict:
ret.append(wordlist[lowerCaseDict[queries[i].lower()]])
else:
query = self.ReplacedStr(queries[i])
if query in vowelDict:
ret.append(wordlist[vowelDict[query]])
else:
ret.append("")
return ret
def ReplacedStr(self, str):
str = str.lower()
for v in "aeiou":
str = str.replace(v, '#')
return str