890. Find and Replace Pattern - LeetCode
Question

Solution
题目大意:从字符串数组中找到类型匹配的如xyy,xxx
思路:
举例:words = ["abc","deq","mee","aqq","dkd","ccc"], pattern = "abb"
abb -> 011
abc -> 012
deq -> 012
mee -> 011 匹配
aqq -> 011 匹配
dkd -> 010
ccc -> 000
Java实现:
public List<String> findAndReplacePattern(String[] words, String pattern) {
int[] patternPos = getStrPos(pattern);
List<String> retList = new ArrayList<>();
for (String word : words) {
if (Arrays.equals(getStrPos(word), patternPos)) retList.add(word);
}
return retList;
}
private int[] getStrPos(String str) {
Map<Character, Integer> posMap = new HashMap<>();
char[] arr = str.toCharArray();
int[] posArr = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
if (posMap.get(arr[i]) == null) {
posMap.put(arr[i], i);
}
posArr[i] = posMap.get(arr[i]);
}
return posArr;
}
890. Find and Replace Pattern - LeetCode的更多相关文章
- 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 查找和替换模式
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:/ ...
- Leetcode 890. Find and Replace Pattern
把pattern映射到数字,也就是把pattern标准化. 比如abb和cdd如果都能标准化为011,那么就是同构的. class Solution: def findAndReplacePatter ...
- 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 ...
- Repeated Substring Pattern Leetcode
Given a non-empty string check if it can be constructed by taking a substring of it and appending mu ...
- Word Pattern - LeetCode
Given a pattern and a string str, find if str follows the same pattern. Here follow means a full mat ...
- All LeetCode Questions List 题目汇总
All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...
随机推荐
- 业务网关之AK中心建设
啥是AK AK(Access Key)是一种身份证明,它解决了"资源的使用者是谁"这个问题,比如在生活中,身份证可以证明你是你,而在云计算或程序中,AK能证明你是这个应用的拥有者. ...
- MySQL优化篇(一),我可以和面试官多聊几句吗?——SQL优化流程与优化数据库对象
我可以和面试官多聊几句吗?只是想偷点技能过来.MySQL优化篇(基于MySQL8.0测试验证),上部分:优化SQL语句.数据库对象,MyISAM表锁和InnoDB锁问题. MyISAM表锁和InnoD ...
- pycharm2019版本可用破解
1.下载破解文件 点击链接https://pan.baidu.com/s/1FbpXC4-rACrLMfeuVzJGPQ 提取码:hyed 下载补丁文件jetbrains-agent.jar并将它 ...
- 分压杯频LLC变换器
- 在原生CSS中使用变量
本文首发于我的博客 一直以来,CSS作为一种申明式的样式标记语言,很难像如javascript等命令式编程语言一样通过定义和使用变量的方式来维护和追踪某些状态.后来随着scss,less等CSS预处理 ...
- 后端渲染神器!Dust
Dust一个适用于浏览器与node的异步模板框架. 先上实例 后端模板: {@inject api="http://api.myserver.com/get_message"} & ...
- android SQLite数据库(转)
Android数据库 之 SQLite数据库 Android数据库 一.关系型数据库SQLIte 每个应用程序都要使用数据,Android应用程序也不例外,Android使用开源的.与操作系统无 ...
- 【Android开发】安卓炫酷效果集合
1. android-ripple-background 能产生波浪效果的背景图片控件,可以自定义颜色,波浪扩展的速度,波浪的圈数. github地址 2. android-shapeLoadingV ...
- Android去掉标题头
在AndroidManifest.xml文件中定义 <application android:theme="@android:style/Theme.NoTitleBar"& ...
- Math类、Random类、System类、BigInteger类、BigDecimal类、Date类、SimpleDateFormat、Calendar类
Math类* A:Math类概述 * Math 类包含用于执行基本数学运算的方法,如初等指数.对数.平方根和三角函数. * B:成员方法 * public static int abs(int a) ...