class Solution(object):
def spellchecker(self, wordlist: 'List[str]', queries: 'List[str]') -> 'List[str]':
wordlen = len(wordlist)
wordict = {}#存原始形式
wordict_lowercase = {}#存小写形式
wordict_replace = {}#存替换形式
for i in range(wordlen):
word = wordlist[i]
if word not in wordict:
wordict.update({word:i}) lowcase = wordlist[i].lower()
#if lowcase not in wordict_lowercase and lowcase != word:
if lowcase not in wordict_lowercase:
wordict_lowercase.update({lowcase:i}) altercase = ''
for j in range(len(lowcase)):
c = lowcase[j]
if c=='e' or c =='i' or c =='o' or c=='u':
c ='a'
altercase += c
if altercase not in wordict_replace:
wordict_replace.update({altercase:i})
'''
print(wordict)
print(wordict_lowercase)
print(wordict_replace)
'''
result = list()
for i in range(len(queries)):
q = queries[i]
lowq = q.lower() alterq = ''
for j in range(len(lowq)):
c = lowq[j]
if c == 'e' or c == 'i' or c == 'o' or c =='u':
c = 'a'
alterq += c
if q in wordict:
result.append(wordlist[wordict[q]])
elif lowq in wordict_lowercase:
result.append(wordlist[wordict_lowercase[lowq]])
elif alterq in wordict_replace:
result.append(wordlist[wordict_replace[alterq]])
else:
result.append('')
return result

leetcode966的更多相关文章

  1. [Swift]LeetCode966.元音拼写检查器 | Vowel Spellchecker

    Given a wordlist, we want to implement a spellchecker that converts a query word into a correct word ...

随机推荐

  1. Redis管道功能

    Redis管道,Redis存储用户浏览数据 当频繁的存储获取Redis数据库中的数据时,可以使用Redis的pipeline(管道)功能,将多个相互没有依赖关系的读写操作,如:下一步执行的Redis操 ...

  2. python 和python-m 的区别

    首先在python自带的,help命令中,可以看到,官方的说明是:-m mod : run library module as a script (terminates option list) 意思 ...

  3. Apache HTTP Server 与 Apache Tomcat 的区别

    要明白他们之间的区别,我们首先需要明白HTTP协议.HTML页面.JSP.Servlet之间的区别和联系. HTTP协议是在TCP/IP协议之上的应用层协议,用以在客户端和服务器之间传递信息.一般传递 ...

  4. vue实现原理

    1.数据监控(data):监听data属性: new Vue之后内部扫描data属性值,用 Object.defineProperty(obj,name,{ set:value=>{ obj[_ ...

  5. Centos 6.9 install Python3.7

    # install python3sudo yum -y updatesudo yum -y install yum-utils yum install -y zlib-devel bzip2-dev ...

  6. discuz 模板中使用方法和语言标签

    一.如何调用方法? 关于模板中eval的使用{eval php 语句} 比如:<!--{eval echo "Hello World!"}--> 例如在discuz的手 ...

  7. vue插件大全汇总

    Vue是一个构建数据驱动的 web 界面的渐进式框架.Vue.js 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件特别整理了常用的vue插件,来了个大汇总,方便查找使用,便于工作 ...

  8. Windows FFMPEG开发环境配置

    1.去FFMPEG网站上下载Dev版本的库,里面有我们需要的头文件和lib文件,然后下载Shared版本的库,里面有我们需要的dll文件 http://ffmpeg.zeranoe.com/build ...

  9. python之路——22

    学习内容 1.初识面向对象 类:抽象的,模子 对象:具体的,根据类规范 代码精简,修改方便,属性规范2.对象 查看属性 调用方法 __dict__,增删改查,通过字典语法进行3.类名 1.实例化 2. ...

  10. 常用font-family

    微软雅黑: Microsoft YaHei 宋体:SimSun 黑体:SimHei 仿宋: FangSong 楷体:  KaiTi 隶书:LiSu 幼圆:YouYuan 华文细黑:STXihei 华文 ...