Skip to content

Commit e8592c2

Browse files
committed
Time: 15 ms (66.47%), Space: 45.8 MB (23.44%) - LeetHub
1 parent b4812ba commit e8592c2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

0 commit comments

Comments
 (0)