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): "& ...
随机推荐
- 第三课 Makefile文件的制作(上)
1.序言: 前面的课程讲解了从gcc编译过程到其实践,大家可以看到其实在这些步骤中有些是可以简化编译的,但由于参数多以及项目中文件数量多的原因难免会造成错误甚至是浪费大量的时间在这编译上,为此linu ...
- 利用开源的TaskScheduler组件实现监控和管理windows计划任务
对于计划任务的执行有很多种解决方案,如利用开源Quartz作业调度框架,在SQL Server的作业等等,同时Windows的任务计划程序功能也很强大,利用此可以很方便的实现很多计划任务,除了人工进行 ...
- 类型“Microsoft.Office.Interop.Word.ApplicationClass”未定义构造函数
错误 4317 无法嵌入互操作类型“Microsoft.Office.Interop.Word.ApplicationClass”.请改用适用的接口. 类型“Microsoft.Office.Inte ...
- 通过自动回复机器人学Mybatis:OGNL+log4j.properties
imooc视频学习笔记 ----> URL:http://www.imooc.com/learn/154 OGNL规则: 从哪里取?(作用域.取值范围,例如封装入一个对象,该对象就是取值范围) ...
- C++结构体定义和C的区别
对于C来说,struct定义的结构体不是一种数据类型,所以每次声明的时候需要加上struct让编译器知道这是结构体,为了不每次都加上struct关键字,可以在定义结构体的时候加上typedef关键字: ...
- NOIP 转圈游戏
描述 n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 1 号位置,……,依此类推 ...
- [Bzoj]5343: [Ctsc2018]混合果汁
5343: [Ctsc2018]混合果汁 题目描述 小 R 热衷于做黑暗料理,尤其是混合果汁. 商店里有 \(n\) 种果汁,编号为 \(0,1,\cdots,n-1\) .\(i\) 号果汁的美味度 ...
- VMware Workstation 12 增加磁盘容量 Windows Server 2012 系统
1.安装虚拟机后,检查C盘容量大小,发现C盘现在的空间是59.9GB,如下图: 2.使用window+R键,出现运行窗口,输入‘cmd’——>‘cd C:\Program Files (x86) ...
- MVC bootstrap 实现 bootstrap table 左右传递数据
源码: @{ ViewBag.Title = "Index"; } @using BC.Platform.UPMS.Models; <!DOCTYPE html> &l ...
- NO.3 Android SDK 高效更新
一.修改协议 SDK Manager下Tools->Options,选中 “Force https://… sources to be fetched using http://…” 既 ...