Untitled

 avatar
unknown
plain_text
a year ago
713 B
3
Indexable
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"; 
    }
};
Editor is loading...
Leave a Comment