forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0966.py
More file actions
17 lines (16 loc) · 704 Bytes
/
Copy path0966.py
File metadata and controls
17 lines (16 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import re
class Solution:
def spellchecker(self, wordlist, queries):
"""
:type wordlist: List[str]
:type queries: List[str]
:rtype: List[str]
"""
words = {w: w for w in wordlist}
cap = {w.lower(): w for w in wordlist[::-1]}
vowel = {re.sub("[aeiou]", '#', w.lower()): w for w in wordlist[::-1]}
return [words.get(w) or cap.get(w.lower()) or vowel.get(re.sub("[aeiou]", '#', w.lower()), "") for w in queries]
if __name__ == "__main__":
wordlist = ["KiTe","kite","hare","Hare"]
queries = ["kite","Kite","KiTe","Hare","HARE","Hear","hear","keti","keet","keto"]
print(Solution().spellchecker(wordlist, queries))