用模式的每个字母去当做key对应单词列表的每个字母value,

如果放进dict之前检测到key已经存在,就检测Word[i][j]是否是和已经存在的value一致,不一致就代表不匹配,break检查下一个Word

还有可能不一样的key对应了一样的value,这种情况也要去掉,把dict的value去重一下,比较长度有没有变化,没有变化就代表匹配,最后输出结果。

 class Solution(object):
def findAndReplacePattern(self, words, pattern):
"""
:type words: List[str]
:type pattern: str
:rtype: List[str]
"""
result = []
a = []
flag = True
for i in range(len(words)):
dic = {}
for j in range(len(words[i])):
if pattern[j] not in dic:
dic[pattern[j]] = words[i][j]
elif dic[pattern[j]] != words[i][j]:
flag = False
break
z = set(dic.values()) if flag and len(z) == len(dic):
result.append(words[i])
a.append(dic)
flag = True
return result

leetcode 890. 查找和替换模式 Python的更多相关文章

  1. [LeetCode] 890. Find and Replace Pattern 查找和替换模式

    You have a list of words and a pattern, and you want to know which words in words matches the patter ...

  2. [Swift]LeetCode890. 查找和替换模式 | Find and Replace Pattern

    You have a list of words and a pattern, and you want to know which words in words matches the patter ...

  3. 【python cookbook】【字符串与文本】6.以不区分大小写的方式对文本做查找和替换

    问题:以不区分大小写的方式对文本做查找和替换 解决方法:使用re模块,并对各种操作都添加上re.IGNORECASE标记 text='UPPER PYTHON,lower python,Mixed P ...

  4. 【python cookbook】【字符串与文本】5.查找和替换文本

    问题:对字符串中的文本做查找和替换 解决方案: 1.对于简单模式:str.replace(old, new[, max]) 2.复杂模式:使用re模块中的re.sub(匹配的模式, newstring ...

  5. [LeetCode] Find And Replace in String 在字符串中查找和替换

    To some string S, we will perform some replacement operations that replace groups of letters with ne ...

  6. Linux中在vim/vi模式下对文本的查找和替换

    查找: 1.vim  filename  进入一般模式下 2.查找和替换方法 /word    向下查找word 的字符串  例如  /chengtingting   向下查找字符chengtingt ...

  7. [Python] Pandas 对数据进行查找、替换、筛选、排序、重复值和缺失值处理

    目录 1. 数据文件 2. 读数据 3. 查找数据 4. 替换数据 4.1 一对一替换 4.2 多对一替换 4.3 多对多替换 5. 插入数据 6. 删除数据 6.1 删除列 6.2 删除行 7. 处 ...

  8. 【python】Leetcode每日一题-132模式

    [python]Leetcode每日一题-132模式 [题目描述] 给定一个整数序列:a1, a2, ..., an,一个132模式的子序列 ai, aj, ak 被定义为:当 i < j &l ...

  9. Java实现 LeetCode 833 字符串中的查找与替换(暴力模拟)

    833. 字符串中的查找与替换 对于某些字符串 S,我们将执行一些替换操作,用新的字母组替换原有的字母组(不一定大小相同). 每个替换操作具有 3 个参数:起始索引 i,源字 x 和目标字 y.规则是 ...

随机推荐

  1. Java中栈的应用,括号匹配

    package edu.yuliang.Data_Structure_Basics; import org.omg.PortableInterceptor.SYSTEM_EXCEPTION; /* 给 ...

  2. ionic 3.0中使用原生插件ionic-native

    作为一个ionic的新手,今天使用了ionic的原生粘贴板插件  @ionic-native/clipboard,根据ionic官方文档上执行的命令 $ ionic cordova plugin ad ...

  3. Python第九课学习

    Python第九课学习 数据结构: 深浅拷贝 集合set 函数: 概念 创建 参数 return 定义域 www.cnblogs.com/yuanchenqi/articles/5782764.htm ...

  4. 【oracle】生成AWR报告

    [第一步]找到awrrpt.sql文件 [ora11g@vm-kvm11820-app ~]$ locate awrrpt.sql /DATA/opt/app/ora11g/product//rdbm ...

  5. .net 程序 动态 控制IIS 站点域名绑定

    第一步:引用 导入 System.EnterpriseServices及System.DirectoryServices 两个引用 程序引用: using System.DirectoryServic ...

  6. Learning Structured Representation for Text Classification via Reinforcement Learning 学习笔记

    Representation learning : 表征学习,端到端的学习 pre-specified  预先指定的 demonstrate  论证;证明,证实;显示,展示;演示,说明 attempt ...

  7. UNION ALL 心得

    TABLE_A 表 UNION ALL TABLE_B 表 UNION 或者 UNION ALL 之后 1.字段长度 必须相同  (如A 10 个列,则B 也要10个列) 2.查询条件也要相同  (A ...

  8. rem 自适应适配方法

    rem是指相对于根元素(html)的字体大小的单位,它是一个相对单位,它是css3新增加的一个单位属性,我们现在有很多人用的都是px,但px是一个绝对单位,遇到分辨率不同的设备,做出的页面可能会乱,这 ...

  9. ewfwefwefe

    qwdefwef fwefwef

  10. [Java Web学习]Tomcat启动时报war exploded: Error during artifact deployment

    报错:Artifact FirstWeb:war exploded: Error during artifact deployment. See server log for details. SEV ...