1
2
3
4
5
6
7
8
9
10
11
12
13
14
| impl Solution {
pub fn add_minimum(word: String) -> i32 {
match word.as_bytes() {
[b'c', ..] => Solution::add_minimum(String::from(&word[1..])) + 2,
[b'b', b'c', ..] => Solution::add_minimum(String::from(&word[2..])) + 1,
[b'b', ..] => Solution::add_minimum(String::from(&word[1..])) + 2,
[b'a', b'b', b'c', ..] => Solution::add_minimum(String::from(&word[3..])),
[b'a', b'b', ..] => Solution::add_minimum(String::from(&word[2..])) + 1,
[b'a', b'c', ..] => Solution::add_minimum(String::from(&word[2..])) + 1,
[b'a', ..] => Solution::add_minimum(String::from(&word[1..])) + 2,
_ => 0,
}
}
}
|