1
class Solution {
2
public boolean canTransform(String start, String end) {
3
int startL = 0, startR = 0;
4
int endL = 0, endR = 0;
5
String stLR = "", edLR = "";
6
for (int i = 0; i < start.length(); i++) {
7
if (start.charAt(i) != 'X') {
8
if (start.charAt(i) == 'L') {
9
startL++;
10
} else {
11
startR++;
12
}
13
stLR += start.charAt(i);
14
}
15
if (end.charAt(i) != 'X') {
16
if (end.charAt(i) == 'L') {
17
endL++;
18
} else {
19
endR++;
20
}
21
edLR += end.charAt(i);
22
}
23

24
if (startL > endL || startR < endR) // Check conditions at each instant
25
return false;
26
}
27

28
if (startL != endL
29
|| startR != endR
30
|| !stLR.equals(edLR)) // check their final count and positions
31
return false;
32

33
return true;
34
}
35
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0