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