当前位置:网站首页>890. find and replace mode
890. find and replace mode
2022-06-12 11:14:00 【anieoo】
Original link :890. Find and replace patterns
Solution:
Use two arrays , When traversing a string ,words[i] Store word to pattern string mappings ,pattern[i] Storage mode string to word mapping .
class Solution {
public:
vector<string> findAndReplacePattern(vector<string>& words, string pattern) {
int n = words.size();
vector<string> res; // Return value
for(int i = 0;i < n;i++) {
if(check(words[i], pattern)) res.push_back(words[i]);
}
return res;
}
bool check(const string &str,const string &patt) {
int words[26],pattern[26];
memset(words, -1, sizeof(words));
memset(pattern, -1, sizeof(pattern));
for(int i = 0;i < str.size();i++) {
int st = str[i] - 'a';
int ts = patt[i] - 'a';
if(words[st] == -1 && pattern[ts] == -1) { // If the letters are not mapped , Store the mapping relationship between letters
words[st] = ts;
pattern[ts] = st;
}
else if(words[st] != ts || pattern[ts] != st) { // Determine whether the mapping relationship is correct
return false;
}
}
return true;
}
};边栏推荐
猜你喜欢

DS18B20 digital thermometer (I) electrical characteristics, parasitic power supply mode and remote wiring

Malicious code analysis practice - lab06-01 exe~Lab06-04. Exe dynamic analysis

网络的拓扑结构

InfoQ geek media's 15th anniversary solicitation |position:fixed virtual button cannot take effect after being triggered. Problem analysis and Solution Exploration

mysql中的索引show index from XXX每个参数的意义

890. 查找和替换模式

AcWing 131. The largest rectangle in the histogram (monotone stack classic application template)

卡鱼刺别再喝醋吞米饭了!教你2招,让鱼刺安全“跑出来”

Mcuxpresso develops NXP rt1060 (3) -- porting lvgl to NXP rt1060

UI自动化测试中比较少见的异常记录
随机推荐
scanf返回值被忽略的原因及其解决方法
Distributed storage exploration
Common port description
JS obtains the time period of this week and last week (one time period is from Monday to Sunday)
LVS基于应用层的健康状态检测
AI - face
How to upload the video on the computer to the mobile phone without network
(37) How bee uses different data source instances at the same time
(三十七)Bee如何同时使用不同数据源实例
AI - face
Common configuration commands for Cisco network device security management
Zabbix 监控之LLD
AcWing 1995. Meet and greet (simulation)
redis 总结
file_ get_ Contents() JSON after reading_ Decode cannot be converted to array
^34作用域面试题
Epidemic home office experience | community essay solicitation
【CF1392D】D. Omkar and Bed Wars(环形与后效性dp)
AcWing 1921. Rearranging cows (ring diagram)
rosbridge使用案例心得总结之_第26篇在同一个服务器上打开多个rosbridge服务监听端口