Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. class Solution {
  2. public:
  3. vector<string> findAndReplacePattern(vector<string>& words, string pattern) {
  4. int flag=0;
  5. int x;
  6. string number="0";
  7. for(int i=1;i<pattern.size();i++){
  8. for(int k=0;k<i;k++){
  9. if(pattern[i]==pattern[k]){
  10. flag=1;
  11. x=number[k]-'0';
  12. number += to_string(x);
  13. }
  14. }
  15. if(flag==0){
  16. x=number[i-1]-'0';
  17. x++;
  18. number+=to_string(x);
  19. }
  20. }
  21. for(int j=0;j<words.size();j++){
  22. flag=0;
  23. string num2 = "0";
  24. for(int i=1;i<words[j].size();i++){
  25. for(int k=0;k<i;k++){
  26. if(words[j][i]==words[j][k]){
  27. flag=1;
  28. x=num2[k]-'0';
  29. num2 += to_string(x);
  30. }
  31. }
  32. if(flag==0){
  33. x=num2[i-1]-'0';
  34. x++;
  35. num2+=to_string(x);
  36. }
  37. }
  38. if(number!=num2){
  39. words.erase(words.begin()+j);
  40. j--;
  41. }
  42. }
  43. return words;
  44. }
  45. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement