Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
713 B
0
Indexable
Never
class Solution {
public:
    string predictPartyVictory(string senate) {
        int n=senate.size();
        queue<int>rad,dir;
        for(int i=0;i<n;i++){
            if(senate[i]=='R'){
                rad.push(i);
            }else{
                dir.push(i);
            }
        }

        while(!rad.empty() && !dir.empty()){
            if(rad.front()<dir.front()){
                dir.pop();
                rad.pop(); 
                rad.push(n);
            }else{
                rad.pop();
                dir.pop();
                dir.push(n);
            }
            n++;
        }
        if(rad.empty()) return "Dire";
        else return "Radiant"; 
    }
};
Leave a Comment