精華區beta Marginalman 關於我們 聯絡資訊
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) } } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.248.143.172 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1696235660.A.7BB.html
Rushia: 大師 10/02 16:34
yam276: 垃圾題目 我一開始還當成對局在寫遞迴跟DP 10/02 16:38
ZooseWu: 大師 10/02 16:56