Skip to content

Commit c6b7596

Browse files
Merge pull request gzc426#9 from EngineerZhang/EngineerZhang-patch-5
Create 神秘的火柴人.md
2 parents 95ff1f7 + df12df5 commit c6b7596

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
};

0 commit comments

Comments
 (0)