-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.rs
52 lines (46 loc) · 1.42 KB
/
main.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
fn main() {
Solution::minimum_moves("XXX".into());
let string = "1234567";
let mut chars = string.chars();
let sub_string = (0..)
.map(|_| chars.by_ref().take(2).collect::<String>())
.take_while(|s| !s.is_empty())
.collect::<Vec<_>>();
let words: [&str; 4] = ["hello", "world", "of", "Rust"];
let mut words: std::array::IntoIter<&str, 4> = words.into_iter();
let a: &mut std::array::IntoIter<&str, 4> = words.by_ref();
let b = words.take(3);
let c = a.take(3);
// Take the first two words.
let hello_world: Vec<_> = a.take(2).collect();
assert_eq!(hello_world, vec!["hello", "world"]);
// Collect the rest of the words.
// We can only do this because we used `by_ref` earlier.
// let of_rust: Vec<_> = words.collect();
// assert_eq!(of_rust, vec!["of", "Rust"]);
}
struct Solution {}
impl Solution {
pub fn minimum_moves(s: String) -> i32 {
let mut s = s.chars();
let mut res = 0;
while let Some(x) = s.next() {
if x == 'X' {
s.next();
s.next();
res += 1;
}
}
res
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn basic() {
assert_eq!(Solution::minimum_moves("XXX".into()), 1);
assert_eq!(Solution::minimum_moves("XXOX".into()), 2);
assert_eq!(Solution::minimum_moves("OOOO".into()), 0);
}
}