Skip to content

Commit e838742

Browse files
authored
Create 2337-move-pieces-to-obtain-a-string.js
1 parent 631ba8e commit e838742

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @param {string} start
3+
* @param {string} target
4+
* @return {boolean}
5+
*/
6+
const canChange = function(start, target) {
7+
const n=target.length;
8+
let i=0,j=0;
9+
while(i<=n && j<=n){
10+
11+
while(i<n && target[i]==='_') i++;
12+
while(j<n && start[j]==='_') j++;
13+
14+
if(i===n || j===n){
15+
return i===n && j===n;
16+
}
17+
18+
if(target[i]!==start[j]) return false;
19+
20+
if(target[i]==='L'){
21+
if(j<i) return false;
22+
}
23+
else{
24+
if(i<j) return false;
25+
}
26+
27+
i++;
28+
j++;
29+
}
30+
return true;
31+
};

0 commit comments

Comments
 (0)