作者:
yam276 ('_')
2023-10-02 16:34:182038. Remove Colored Pieces if Both Neighbors are the Same Color
兩個人負責A跟B
輪流把字串中 各自負責的字母連續三個變成連續兩個
誰不能操作誰就輸 永遠是A先手
思路:
這題不是博弈題
只要輪流操作計次
判斷最後A次數是否大於B次數就好
Code:
impl Solution {
pub fn winner_of_game(colors: String) -> bool {
let mut a_count = 0;
let mut b_count = 0;
let bytes = colors.as_bytes();
for index in 2..colors.len() {
if bytes[index] == bytes[index - 1] &&
bytes[index] == bytes[index - 2] {
if bytes[index] == b'A' {
a_count += 1;
} else {
b_count += 1;
}
}
}
(a_count > b_count)
}
}