2026/2/12 8:12:39
网站建设
项目流程
海外建站,网站建设公司行情,南宁高端网站建设,网页界面设计特点Problem:890. Find and Replace Pattern 查找和替换模式 耗时100%#xff0c;要形成单一映射#xff0c;也就是一对一#xff0c;不能一对多也不能多对一#xff0c;所以需要两个哈希表记录映射关系#xff0c;确保两者是一一映射 Code
class Solution {
public:int ch[2…Problem:890. Find and Replace Pattern 查找和替换模式耗时100%要形成单一映射也就是一对一不能一对多也不能多对一所以需要两个哈希表记录映射关系确保两者是一一映射Codeclass Solution { public: int ch[26], cw[26]; vectorstring findAndReplacePattern(vectorstring words, string pattern) { vectorstring ret; int a, find; for(int i 0; i words.size(); i) { memset(ch, 0, sizeof(ch)); memset(cw, 0, sizeof(cw)); find 1; for(int j 0; j pattern.size(); j) { if(ch[words[i][j]-a] 0 cw[pattern[j] - a]0) { ch[words[i][j]-a] pattern[j] - a 1; cw[pattern[j] - a] words[i][j]-a 1; } else if(ch[words[i][j]-a] ! 0) { if(ch[words[i][j]-a] ! pattern[j] - a 1) { find -1; break; } } else { if(cw[pattern[j] - a] ! words[i][j]-a 1) { find -1; break; } } } if(find 0) { ret.push_back(words[i]); } } return ret; } };