当前位置:网站首页>Leetcode 890 finding and replacing patterns [map] the leetcode path of heroding
Leetcode 890 finding and replacing patterns [map] the leetcode path of heroding
2022-06-12 23:00:00 【HERODING23】

Their thinking :
In essence, it is to solve a bi-directional mapping problem , For each word and pattern Every letter in , Must be bi-directional mapping , Like weight mee and abb, must e and b Corresponding , And b and e Corresponding , This requires the construction of two arrays to store word The corresponding letter subscript and pattern The mapping of the corresponding letter subscript in , as well as pattern The corresponding letter subscript and word The mapping of the corresponding letter subscript in , If they can all correspond to , be word Satisfy the matching pattern , Put in res Array , Otherwise directly break, The code is as follows :
class Solution {
public:
vector<string> findAndReplacePattern(vector<string>& words, string pattern) {
vector<string> res;
int len = pattern.size();
for(auto& word : words) {
vector<int> reflect1(26, -1);
vector<int> reflect2(26, -1);
int flag = true;
for(int i = 0; i < len; i ++) {
if(reflect1[word[i] - 'a'] == -1 && reflect2[pattern[i] - 'a'] == -1) {
reflect1[word[i] - 'a'] = pattern[i] - 'a';
reflect2[pattern[i] - 'a'] = word[i] - 'a';
} else {
if(reflect1[word[i] - 'a'] == pattern[i] - 'a' && reflect2[pattern[i] - 'a'] == word[i] - 'a') {
continue;
} else {
flag = false;
break;
}
}
}
if(flag) {
res.emplace_back(word);
}
}
return res;
}
};
边栏推荐
- 【Web技术】1348- 聊聊水印实现的几种方式
- 【LeetCode】102. 二叉树的层序遍历
- 細數攻防演練中十大關鍵防守點
- Analysis report on business model innovation path and operation status of China's app store industry from 2022 to 2028
- C language: how to give an alias to a global variable?
- ImageView grayed, reflected, rounded, watermarked
- China's elastic belt market trend report, technical dynamic innovation and market forecast
- Flutter series part: detailed explanation of GridView layout commonly used in flutter
- Lua date time
- What you must know about cloud computing
猜你喜欢

Insight into China's smart medical industry in 2022

Colab tutorial (super detailed version) and colab pro/colab pro+ usage evaluation
C语言:如何给全局变量起一个别名?

设计消息队列存储消息数据的 MySQL 表格

管线中的坐标变换

ShardingSphere-proxy-5.0.0部署之分表实现(一)

Colab教程(超级详细版)及Colab Pro/Colab Pro+使用评测

ASP. Net core Middleware

Coordinate transformation in pipelines

Embedded pipeline out of the box
随机推荐
JVM foundation > G1 garbage collector
Colab tutorial (super detailed version) and colab pro/colab pro+ usage evaluation
JVM Basics - > What are the JVM parameters?
C # reading table data in word
QT quick 3D learning: use mouse and keyboard to control node position and direction
China Aquatic Fitness equipment market trend report, technical innovation and market forecast
Web3 principle and decentralization
Several Tsinghua students I know have left
项目里面的traceID的设计
Analysis report on business model innovation path and operation status of China's app store industry from 2022 to 2028
JVM Basics - > how GC determines that an object can be recycled
Analysis report on investment and development trend of gap base of Chinese traditional medicine 2022 ~ 2028
[Part VI] source code analysis and application details of countdownlatch [key]
Is it safe to open an account for flush stock account
【LeetCode】53.最大子数组和
lua 条件语句
JVM foundation - > three ⾊ mark
MYSQL 行转列、列转行、多列转一行、一行转多列
Gb28181 protocol -- alarm
MOOG servo valve d634-341c/r40ko2m0nss2