File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ vector<string > findAndReplacePattern(vector<string >& words, string pattern) {
4
+ vector<string > ret;
5
+
6
+ int size = words.size();
7
+ int n = pattern.length();
8
+
9
+ for(int i=0; i<size; i++)
10
+ {
11
+ map<char, char> m;
12
+ map<char, char> m1;
13
+ int j = 0;
14
+ for(j=0; j<n; j++)
15
+ {
16
+ if(m.find(pattern[j])==m.end())
17
+ {
18
+ m[pattern[j]] = words[i][j];
19
+ }
20
+
21
+ if(m1.find(words[i][j])==m1.end())
22
+ {
23
+ m1[words[i][j]] = pattern[j];
24
+ }
25
+
26
+ if(m.find(pattern[j])!=m.end() && m[pattern[j]] != words[i][j])
27
+ break;
28
+
29
+ if(m1.find(words[i][j])!=m.end() && m1[words[i][j]]!=pattern[j])
30
+ break;
31
+
32
+ }
33
+
34
+ if(j == n)
35
+ ret.push_back(words[i]);
36
+ }
37
+
38
+ return ret;
39
+ }
40
+ };
You can’t perform that action at this time.
0 commit comments