Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<string> findMatchedWords(vector<string> dict,string pattern)
- {
- //Your code here
- unordered_map<char,int> m;
- vector<string> ans;
- int count = 1;
- string p = "";
- for(char c : pattern){
- if(m.find(c)==m.end()){
- m.insert({c,count});
- count++;
- }
- p += to_string(m.find(c)->second);
- }
- for(string d : dict){
- unordered_map<char,int> mp;
- count = 1;
- string t = "";
- for(char c : d){
- if(mp.find(c)==mp.end()){
- mp.insert({c,count});
- count++;
- }
- t += to_string(mp.find(c)->second);
- }
- if(t==p)ans.push_back(d);
- }
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement