-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmove-pieces-to-obtain-a-string.rs
55 lines (44 loc) · 1.22 KB
/
move-pieces-to-obtain-a-string.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#![allow(dead_code, unused, unused_variables, non_snake_case)]
fn main() {}
struct Solution;
impl Solution {
pub fn can_change(start: String, target: String) -> bool {
let (start, target) = (start.as_bytes(), target.as_bytes());
let (mut i, mut j) = (0, 0);
while i < start.len() && j < target.len() {
while i < start.len() && start[i] == b'_' {
i += 1;
}
while j < target.len() && target[j] == b'_' {
j += 1;
}
if i >= start.len() || j >= target.len() {
break;
}
if start[i] != target[j] {
return false;
}
match start[i] {
b'L' if i < j => return false,
b'R' if i > j => return false,
_ => {
i += 1;
j += 1;
}
}
}
while i < start.len() {
if start[i] != b'_' {
return false;
}
i += 1;
}
while j < target.len() {
if target[j] != b'_' {
return false;
}
j += 1;
}
true
}
}