Skip to content

Commit d49df60

Browse files
authored
Create Solution.java
1 parent a7dbc80 commit d49df60

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public boolean canTransform(String start, String end) {
3+
if (start.length() != end.length()) {
4+
return false;
5+
}
6+
int i = 0, j = 0;
7+
while (true) {
8+
while (i < start.length() && start.charAt(i) == 'X') {
9+
++i;
10+
}
11+
while (j < end.length() && end.charAt(j) == 'X') {
12+
++j;
13+
}
14+
if (i == start.length() && j == start.length()) {
15+
return true;
16+
}
17+
if (i == start.length() || j == start.length() || start.charAt(i) != end.charAt(j)) {
18+
return false;
19+
}
20+
if (start.charAt(i) == 'L' && i < j || start.charAt(i) == 'R' && i > j) {
21+
return false;
22+
}
23+
++i;
24+
++j;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy