把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. 笔记-CSS空背景图片会导致页面被加载两次

    如果页面样式的背景图片路径设置为'' 或 '#', 会导致页面被重复加载两次 (Chrome.56.0.2924.87 测试) 因为:空图片路径属性值,默认加载当前页面的URL作为图片路径 Safar ...

  2. 【笔记】c++文件

    1.文件. #include <iostream> #include <cstdio> #include <string> #include <cstring ...

  3. 如何用纯 CSS 创作一个小球上台阶的动画

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/PBGJwL 可交互视频 ...

  4. undefined symbol: PyUnicodeUCS4_AsUTF8String

    python 默认是ucs2编码进行编译,重新编译使用ucs4. python:     ./configure --enable-unicode=ucs4        make && ...

  5. 20145109《Java程序设计》第一周学习总结

    20145109 <Java程序设计>第一周学习总结 教材学习内容总结 About JVM, JRE, JDK JVM包含于JRE中,用于运行Java程序.JDK用于开发Java程序,包含 ...

  6. 将CString写入到本地文件中

    void SocketU::WritePacket2File(CString packet_str)//packet_str为待写入的字符串{ CTime time = CTime::GetCurre ...

  7. 混合开发的大趋势之 一个Android程序员眼中的 React.js 块级作用域 和 let

    转载请注明出处:王亟亟的大牛之路 最近都有事干然后,快到月底了这个月给CSDN的博文也就两篇,想想也蛮多天没更了,那就来一篇. 老规矩,先安利:https://github.com/ddwhan012 ...

  8. redis入门笔记

    redis入门笔记 参考redis实战手册 1. Redis在windows下安装 下载地址:https://github.com/MSOpenTech/redis/tags 安装Redis 1.1. ...

  9. js异步获取数据的问题

    最近做js开发的时候发现了很多哥们不能区分同步和异步的区别,典型的在ajax部分,在该ajax为异步操作的时候,获取不到success之后的data的值,于是产生了各种奇葩的写法.比如创建一个局部变量 ...

  10. php。。。

    我可能不会是一个合格的程序员,因为不够专一,学的种类多,精通的却很少,现在我要做为一个php程序员,专注起航了...接下来半年全力以赴,做出成绩吧. 另外之前的狂刷要一千题也要开始每天更新了,最难的就 ...