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