nikunjsoni

777

Jul 4th, 2021
109
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     bool canTransform(string start, string end) {
  4.       vector<pair<int, int>> s, d;
  5.       for(int i=0; i<start.size(); i++){
  6.         if(start[i] != 'X')
  7.           s.push_back({start[i], i});
  8.       }
  9.       for(int i=0; i<end.size(); i++){
  10.         if(end[i] != 'X')
  11.           d.push_back({end[i], i});
  12.       }
  13.      
  14.       if(s.size() != d.size()) return false;
  15.      
  16.       for(int i=0; i<s.size(); i++){
  17.         if(s[i].first != d[i].first) return false;
  18.         if(s[i].first == 'L' && d[i].second > s[i].second) return false;
  19.         if(s[i].first == 'R' && d[i].second < s[i].second) return false;
  20.       }
  21.       return true;
  22.     }
  23. };
RAW Paste Data