Skip to content

Commit 2bf236d

Browse files
committed
Solution as on 19-03-2022 08:22 am
1 parent f572c37 commit 2bf236d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// 777.✅ Swap Adjacent in LR String
2+
3+
class Solution
4+
{
5+
public:
6+
bool canTransform(string start, string end)
7+
{
8+
int i = 0, j = 0;
9+
10+
while (i < start.size() && j < end.size())
11+
{
12+
while (start[i] == 'X')
13+
++i;
14+
while (end[j] == 'X')
15+
++j;
16+
17+
if (start[i] != end[j])
18+
return 0;
19+
else if (start[i] == 'R' && i > j)
20+
return 0;
21+
else if (start[i] == 'L' && i < j)
22+
return 0;
23+
++i;
24+
++j;
25+
}
26+
while (i < start.size() && start[i] == 'X')
27+
i++;
28+
while (j < end.size() && end[j] == 'X')
29+
j++;
30+
return i == j;
31+
}
32+
};

0 commit comments

Comments
 (0)