Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<string> findAndReplacePattern(vector<string>& words, string pattern) {
- int flag=0;
- int x;
- string number="0";
- for(int i=1;i<pattern.size();i++){
- for(int k=0;k<i;k++){
- if(pattern[i]==pattern[k]){
- flag=1;
- x=number[k]-'0';
- number += to_string(x);
- }
- }
- if(flag==0){
- x=number[i-1]-'0';
- x++;
- number+=to_string(x);
- }
- }
- for(int j=0;j<words.size();j++){
- flag=0;
- string num2 = "0";
- for(int i=1;i<words[j].size();i++){
- for(int k=0;k<i;k++){
- if(words[j][i]==words[j][k]){
- flag=1;
- x=num2[k]-'0';
- num2 += to_string(x);
- }
- }
- if(flag==0){
- x=num2[i-1]-'0';
- x++;
- num2+=to_string(x);
- }
- }
- if(number!=num2){
- words.erase(words.begin()+j);
- j--;
- }
- }
- return words;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement