Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<string> findAndReplacePattern(vector<string>& words, string pattern) {
- char m1[26], m2[26];
- vector<string> res;
- int i;
- for(auto word: words){
- for(i=0; i<26; i++)
- m1[i] = m2[i] = -1;
- for(i=0; i<word.size(); i++){
- int ch1 = word[i]-'a', ch2 = pattern[i]-'a';
- if(m1[ch1] == -1 && m2[ch2] == -1){
- m1[ch1] = ch2;
- m2[ch2] = ch1;
- }
- else
- if(m1[ch1] != ch2 || m2[ch2] != ch1)
- break;
- }
- if(i == word.size()) res.push_back(word);
- }
- return res;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement