File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
2337-move-pieces-to-obtain-a-string Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public boolean canChange (String start , String target ) {
3
+ int i =0 ,j =0 ;
4
+ int n = start .length ();
5
+ while (i <n || j <n ){
6
+ while (i <n && start .charAt (i )=='_' ){
7
+ i ++;
8
+ }
9
+ while (j <n && target .charAt (j )=='_' ){
10
+ j ++;
11
+ }
12
+ //System.out.print("i - "+i+" "+"j -"+j+" , ");
13
+
14
+ if (i == j && i == start .length ()) {
15
+ return true ;
16
+ }
17
+
18
+ //both are not equal :
19
+ if (i == start .length () || j == target .length () || start .charAt (i ) != target .charAt (j )) {
20
+ return false ;
21
+ }
22
+
23
+ //both are equal :
24
+ if ((target .charAt (j )=='L' && i <j ) || (target .charAt (j )=='R' && i >j )){
25
+ return false ;
26
+ }
27
+ i ++;
28
+ j ++;
29
+
30
+
31
+ }
32
+ return true ;
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments