blob: 298c43d9c82ac08ce255e179d0dd2723fd1607ee (
plain)
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
|
fn main() {
println!("Hello, world!");
let tests = [
("AAABABB", true),
("AA", false),
("ABBBBBBBAAA", false),
("AAAABBBB", false)
];
for (input, output) in tests {
let result = Solution::winner_of_game(input.to_string());
println!("{input:?} is {result} should be {output:?}");
}
}
struct Solution;
impl Solution {
pub fn winner_of_game(mut colors: String) -> bool {
if colors.len() < 3 {return false;}
let mut is_alice_turn = true;
while ((is_alice_turn && colors.contains("AAA")) || (!is_alice_turn) && colors.contains("BBB")) {
if is_alice_turn {
colors = colors.replacen("AAA", "AA", 1);
} else {
colors = colors.replacen("BBB", "BB", 1);
}
is_alice_turn = !is_alice_turn
}
!is_alice_turn
}
}
|