Skip to content

Commit d4d2c6b

Browse files
authored
Merge pull request gzc426#160 from wswdwf/patch-6
Create Sagittatius.md
2 parents c7a319d + d6b79e3 commit d4d2c6b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

2018.11.30-leetcode890/Sagittatius.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
```
2+
class Solution {
3+
public:
4+
vector<string> findAndReplacePattern(vector<string>& words, string pattern) {
5+
vector<string> s;
6+
for(int i=0;i<words.size();i++)
7+
{
8+
map<char,char> cmap;
9+
string st="";
10+
bool flag=true;
11+
if(words[i].size()!=pattern.size())
12+
continue;
13+
for(int j=0,k=0;k<pattern.size();j++,k++)
14+
{
15+
if(cmap.find(pattern[k])==cmap.end()&&st.find(words[i][j])==string::npos)
16+
{
17+
cmap[pattern[k]]=words[i][j];
18+
st+=words[i][j];
19+
}
20+
else if(cmap[pattern[k]]!=words[i][j])
21+
{
22+
flag=false;
23+
break;
24+
}
25+
}
26+
if(flag==true)
27+
{
28+
s.push_back(words[i]);
29+
}
30+
}
31+
32+
return s;
33+
}
34+
};
35+
```

0 commit comments

Comments
 (0)