楼主: 
yam276 ('_')   
2025-06-12 18:25:00649. Dota2 Senate
题目:
两党人有行动顺序搞政治斗争
每次行动会大罢免掉敌对党最快行动的人
求最后剩下哪一党的人
思路:
帮他们各自照 index 排序
每次派一个最快的生死斗
赢的人回去最后排队
Code:
use std::collections::VecDeque;
impl Solution {
    pub fn predict_party_victory(senate: String) -> String {
        let mut radiant = VecDeque::new();
        let mut dire = VecDeque::new();
        for (i, c) in senate.chars().enumerate() {
            if c == 'R' {
                radiant.push_back(i);
            } else if c == 'D' {
                dire.push_back(i);
            }
        }
        let n = senate.len();
        while !radiant.is_empty() && !dire.is_empty() {
            if let (Some(r1), Some(d1)) =
                   (radiant.pop_front(), dire.pop_front()) {
                if r1 < d1 {
                    radiant.push_back(r1 + n);
                } else {
                    dire.push_back(d1 + n);
                }
            }
        }
        match radiant.is_empty() {
            true => "Dire".to_string(),
            false => "Radiant".to_string(),
        }
    }
}