Skip to content

Commit 5b85629

Browse files
Create swap_adjacent_in_LR_string.py
1 parent 179e93d commit 5b85629

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

swap_adjacent_in_LR_string.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def canTransform(self, start: str, end: str) -> bool:
3+
if len(start) != len(end): return False
4+
i, j, l = 0, 0, len(start)
5+
while True:
6+
while i < l and start[i] == 'X': i += 1
7+
while j < l and end[j] == 'X': j += 1
8+
if i == l or j == l:
9+
if i == j: return True
10+
return False
11+
if start[i] != end[j]: return False
12+
if start[i] == 'L':
13+
if i < j: return False
14+
#start[i] == 'R'
15+
else:
16+
if i > j: return False
17+
i, j = i+1, j+1def canTransform(self, start: str, end: str) -> bool:
18+

0 commit comments

Comments
 (0)