nikunjsoni

833

Jun 27th, 2021
106
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     string findReplaceString(string S, vector<int>& indexes, vector<string>& sources, vector<string>& targets) {
  4.         vector<pair<int, int>> sorted;
  5.         for(int i = 0 ; i < indexes.size(); i++)
  6.             sorted.push_back({indexes[i], i});
  7.         sort(sorted.rbegin(), sorted.rend());
  8.         for(auto ind : sorted) {
  9.             int i = ind.first;
  10.             string s = sources[ind.second], t = targets[ind.second];
  11.             if(S.substr(i, s.length()) == s)
  12.                 S = S.substr(0, i) + t + S.substr(i + s.length());
  13.         }
  14.         return S;
  15.     }
  16. };
RAW Paste Data