Leetcode 890. Find and Replace Pattern
把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的更多相关文章
- [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 ...
- 890. Find and Replace Pattern - LeetCode
Question 890. Find and Replace Pattern Solution 题目大意:从字符串数组中找到类型匹配的如xyy,xxx 思路: 举例:words = ["ab ...
- 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 ...
- 【LeetCode】890. Find and Replace Pattern 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典+set 单字典 日期 题目地址:https:/ ...
- 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 ...
- [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 ...
- LeetCode算法题-Repeated Substring Pattern(Java实现)
这是悦乐书的第236次更新,第249篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第103题(顺位题号是459).给定非空字符串检查是否可以通过获取它的子字符串并将子字符 ...
- LeetCode 290. 单词规律(Word Pattern) 41
290. 单词规律 290. Word Pattern 题目描述 给定一种规律 pattern 和一个字符串 str,判断 str 是否遵循相同的规律. 这里的 遵循 指完全匹配,例如,pattern ...
- 【leetcode❤python】 290. Word Pattern
#-*- coding: UTF-8 -*-class Solution(object): def wordPattern(self, pattern, str): "& ...
随机推荐
- 查询前几条记录 top limit
SQL Server 数据库中的Top关键字可实现查询数据库表中的前几条数据,但是需要注意的是,Top关键字只能在SQL Server数据库中可以使用,而在MySQL数据库中就要使用具有同样功能的LI ...
- Spring Web MVC 随笔
1.ContextLoaderListener 对于使用Spring的Web应用,无需手动创建Spring容器,而是通过配置文件声明式地创建Spring容器.可以直接在web.xml文件中配置创建Sp ...
- git-bash使用ctrl C无法终止nodemon的执行
原因: git的bug 解决:git版本降级为2.10.0好了
- 属性检测 In,hasOwnPreperty()和propertyIsEnumerable()
IN 左侧是属性名:右侧是对象名, 如果 属性是 自有属性 或者继承属性 则返回 TRUE var o={x:1,y:2} "x" in o 返回 true: hasOw ...
- NFS 安装、管理
NFS简介 NFS允许一个系统在网络上与他人共享目录和文件.通过使用NFS,用户和程序可以像访问本地文件一样访问远程系统上的文件. 安装NFS 服务端安装 NFS安装包:nfs-utils-lib.i ...
- NSwag在asp.net web api中的使用,基于Global.asax
https://github.com/NSwag/NSwag/wiki/OwinGlobalAsax This page explains how to use the NSwag OWIN midd ...
- Effective C++ 条款12:复制对象时勿忘其每一个成分
void logCall(const std::string& funcName); class Customer { public: ... Customer (const Customer ...
- 导出成可运行jar包时所遇问题的解决办法 - 转载
Could not find main method from given launch configuration 当我把我的Java工程导出为可运行的jar包时,遇到了“Could not fin ...
- 2017 湘潭邀请赛&JSCPC G&J
训练的时候对G想了一个假算法..也有很大可能是写错了.. 下来一看别人的G 看起来很奇妙.. 开始把所有的左括号翻成右括号,然后cost*=-1 这样在优先队列中就是最优的 然后for每一段 如果前缀 ...
- Nessus离线安装及升级插件 转
修改Nessus Web端口 ./nessuscli fix --set xmlrpc_listen_port=8866 最近做客户的内网主机漏洞扫描,申请了一台内网主机做扫描服务器,安装Nessus ...