jayati

Match Substring After Replacement

Sep 27th, 2022 (edited)
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     bool matchReplacement(string s, string sub, vector<vector<char>>& mappings) {
  4.  
  5.     int nn=sub.size();
  6.     int n=s.size();
  7.     map<pair<char,char>,int>m;
  8.     for(int i=0;i<mappings.size();i++)
  9.     {
  10.         m[{mappings[i][0],mappings[i][1]}]++;
  11.     }
  12.    
  13.     bool p=false;
  14.     for(int i=0;i<n-nn+1;i++)
  15.     {// set<pair<char,char>>ss;
  16.      bool tt=true;
  17.         for(int j=0;j<nn;j++)
  18.         {
  19.             if(s[i+j]!=sub[j])
  20.             {
  21.                 if(m[{sub[j],s[i+j]}]==0)
  22.                 {
  23.                     tt=false;
  24.                     break;
  25.                 }
  26.             }
  27.            // ss.insert({sub[j],s[i+j]});
  28.         }
  29.      if(tt)
  30.      {
  31.          p=true;
  32.          break;
  33.      }
  34.     }
  35.     return p;
  36. }
  37. };
Advertisement
Add Comment
Please, Sign In to add comment