2337.cpp (566B)
1 class Solution { 2 public: 3 bool canChange(const string &start, const string &target) const { 4 const int n = size(start); 5 int i = 0, j = 0; 6 7 while (i < n || j < n) { 8 while (i < n && start[i] == '_') 9 i++; 10 while (j < n && target[j] == '_') 11 j++; 12 13 if (i == n || j == n) return i == n && j == n; 14 15 if (start[i] != target[j]) return false; 16 if (start[i] == 'R' ? i > j : i < j) return false; 17 18 i++, j++; 19 } 20 21 return true; 22 } 23 };