Move Pieces to Obtain a String LeetCode solution in C++

1
class Solution {
2
public:
3
bool canChange(string s, string t) {
4
int i = 0, j = 0, n = s.size(), m = t.size();
5
if (n != m) return false;
6

7
while (i < n || j < m) {
8
while (i < n && s[i] == '_') i++;
9
while (j < m && t[j] == '_') j++;
10

11
if (s[i] != t[j]) return false;
12
if (s[i] == 'R' && i > j) return false;
13
if (s[i] == 'L' && i < j) return false;
14
i++, j++;
15
}
16
return true;
17
}
18
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0