Skip to content

Commit

Permalink
Create 2337. Move Pieces to Obtain a String (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Dec 5, 2024
2 parents c69a53c + 206e109 commit 5d3fdcb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions 2337. Move Pieces to Obtain a String
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution {
public:
bool canChange(string start, string target) {
int left = 0, right = 0;

for (int i = 0; i < start.size(); i++) {
if (start[i] == 'R') {
right++;
if (left != 0)
return false;
} else if (start[i] == 'L')
left--;
if (target[i] == 'R')
right--;
else if (target[i] == 'L') {
left++;
if (right != 0)
return false;
}
if (left < 0 || right < 0)
return false;
}
return left == 0 and right == 0;
}
};

0 comments on commit 5d3fdcb

Please sign in to comment.