We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents c69a53c + 206e109 commit 5d3fdcbCopy full SHA for 5d3fdcb
2337. Move Pieces to Obtain a String
@@ -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
19
+ }
20
+ if (left < 0 || right < 0)
21
22
23
+ return left == 0 and right == 0;
24
25
+};
0 commit comments