20.12.11 leetcode649

题目链接:https://leetcode-cn.com/problems/dota2-senate/

题意&&分析:说是中等题,结果简单的要命,不提了。

class Solution {
public:
    string predictPartyVictory(string senate) {
        int num1=0,num2=0,diff1=0,diff2=0;
        for(auto& v: senate){
            if(v=='R')num1++;
            if(v=='D')num2++;
        }
        while(1){
        for(auto& v : senate){
            if(v=='N')continue;
            else if(v=='R'){
                if(diff1){
                    diff1--;
                    num1--;
                    v='N';
                    continue;
                }
                diff2++;
            }
            else if(v=='D'){
                if(diff2){
                    diff2--;
                    num2--;
                    v='N';
                    continue;
                }
                diff1++;
            }
            if(num1==0)return "Dire";
            if(num2==0)return "Radiant";
        }
    }
    }
};

 

posted @ 2020-12-11 10:17  清酒令  阅读(85)  评论(0编辑  收藏  举报