Re: [闲聊] 每日LeetCode

楼主: yam276 ('_')   2023-10-02 16:34:18
2038. 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)
}
}
作者: Rushia (みけねこ的鼻屎)   2022-10-02 16:34:00
大师
楼主: yam276 ('_')   2023-10-02 16:38:00
垃圾题目 我一开始还当成对局在写递回跟DP
作者: ZooseWu (N5)   2023-10-02 16:56:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com