File tree Expand file tree Collapse file tree 1 file changed +27
-6
lines changed Expand file tree Collapse file tree 1 file changed +27
-6
lines changed Original file line number Diff line number Diff line change 1
1
```
2
2
class Solution {
3
3
public:
4
- int findDuplicate(vector<int>& nums) {
5
- for(int i=0;i<nums.size();i++)
4
+ vector<string> findAndReplacePattern(vector<string>& words, string pattern) {
5
+ vector<string> s;
6
+ for(int i=0;i<words.size();i++)
6
7
{
7
- if(nums[abs(nums[i])]<0)
8
- return abs(nums[i]);
9
- else
10
- nums[abs(nums[i])]=-nums[abs(nums[i])];
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
+ }
11
30
}
31
+
32
+ return s;
12
33
}
13
34
};
14
35
```
You can’t perform that action at this time.
0 commit comments