把pattern映射到数字,也就是把pattern标准化.

比如abb和cdd如果都能标准化为011,那么就是同构的.

class Solution:
def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]:
p = self.get_pattern(pattern)
ans = []
for w in words:
if self.get_pattern(w) == p:
ans.append(w)
return ans def get_pattern(self, word: str) -> List[int]:
t = 0
dic = {word[0]: t}
ans = []
for v in word[1:]:
if v in dic.keys():
ans.append(dic[v])
else:
t += 1
dic[v] = t
ans.append(dic[v])
return ans

Leetcode 890. Find and Replace Pattern的更多相关文章

  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. 890. Find and Replace Pattern - LeetCode

    Question 890. Find and Replace Pattern Solution 题目大意:从字符串数组中找到类型匹配的如xyy,xxx 思路: 举例:words = ["ab ...

  3. LC 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 ...

  4. 【LeetCode】890. Find and Replace Pattern 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典+set 单字典 日期 题目地址:https:/ ...

  5. 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 ...

  6. [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 ...

  7. LeetCode算法题-Repeated Substring Pattern(Java实现)

    这是悦乐书的第236次更新,第249篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第103题(顺位题号是459).给定非空字符串检查是否可以通过获取它的子字符串并将子字符 ...

  8. LeetCode 290. 单词规律(Word Pattern) 41

    290. 单词规律 290. Word Pattern 题目描述 给定一种规律 pattern 和一个字符串 str,判断 str 是否遵循相同的规律. 这里的 遵循 指完全匹配,例如,pattern ...

  9. 【leetcode❤python】 290. Word Pattern

    #-*- coding: UTF-8 -*-class Solution(object):    def wordPattern(self, pattern, str):        "& ...

随机推荐

  1. Memcached基础介绍

    1.memcached是什么,有什么作用? )memcached是一个开源的.高性能的内存的缓存软件,从名称上看mem就是内存的意思,而cache就是缓存的意思. )memcached通过在事先规划好 ...

  2. rails timeout 异常

    发现经常有”超时“的错误信息,如/usr/lib/ruby/1.8/timeout.rb:54:in `rbuf_fill': execution expired (Timeout::Error),恩 ...

  3. 关于python中的查询数据库内容中用到的fetchone()函数和fetchall()函数(转)还有fetchmany()

    最近在用python操作mysql数据库时,碰到了下面这两个函数,标记一下: fetchone() : 返回单个的元组,也就是一条记录(row),如果没有结果 则返回 None fetchall() ...

  4. Generative model 和Discriminative model

    学习音乐自动标注过程中设计了有关分类型模型和生成型模型的东西,特地查了相关资料,在这里汇总. http://blog.sina.com.cn/s/blog_a18c98e50101058u.html ...

  5. E-R图和数据库的设计

    数据库设计: 原则:如果属性有了多个字段,可以当实体.如果只有一个字段,只能当属性(比如实体属性种类) 1.设计E-R图 实体:矩形 关系:菱形 属性:椭圆(可省) 2.关系的类型 一对一 一对多 多 ...

  6. APP测试的要点

    APP测试要点 功能性 UI界面 安装与卸载 升级 登录测试 离线测试 安全性测试 兼容性(操作系统,屏幕尺寸,分辨率,厂家) 消息推送 前后台切换 网络环境(wifi/2G/3G/4G/无网) 异常 ...

  7. curator的版本兼容问题(需注意)

    Curator 存在版本兼容问题. Curator 2.x.x-兼容两个zk 3.4.x 和zk 3.5.x, Curator 3.x.x-兼容兼容zk 3.5. Versions The are c ...

  8. HDU 1238 Substing

    思路: 1.找出n个字符串中最短的字符串Str[N] 2.从长到短找Str[N]的子子串 subStr[N],以及subStr[N]的反转字符串strrev(subStr[N]):(从长到短是做剪枝处 ...

  9. java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]

    1.问题描述: 对于创建的springboot项目,通过启动类启动,访问没问题,但打成war部署到tomcat上启动报错,如下: 严重: ContainerBase.addChild: start: ...

  10. EYES组——软件体系结构上机规划

    EYES组——软件体系结构上机规划 考勤助手 第九周: 需求分析的详细撰写,并在此基础上探讨与完善,讨论软件的体系结构风格,画出初步的UML类图. 第十周: 选择合适的软件构架风格(3层C/S架构风格 ...