Skip to content

Commit 5d3fdcb

Browse files
authored
Create 2337. Move Pieces to Obtain a String (#652)
2 parents c69a53c + 206e109 commit 5d3fdcb

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

2337. Move Pieces to Obtain a String

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public:
3+
bool canChange(string start, string target) {
4+
int left = 0, right = 0;
5+
6+
for (int i = 0; i < start.size(); i++) {
7+
if (start[i] == 'R') {
8+
right++;
9+
if (left != 0)
10+
return false;
11+
} else if (start[i] == 'L')
12+
left--;
13+
if (target[i] == 'R')
14+
right--;
15+
else if (target[i] == 'L') {
16+
left++;
17+
if (right != 0)
18+
return false;
19+
}
20+
if (left < 0 || right < 0)
21+
return false;
22+
}
23+
return left == 0 and right == 0;
24+
}
25+
};

0 commit comments

Comments
 (0)