[LeetCode] 649. Dota2 Senate
풀이
#include <queue>
class Solution {
public:
string predictPartyVictory(string senate) {
queue<char> game = queue<char>();
int RCount = 0;
int DCount = 0;
for(int i=0; i<senate.length(); ++i){
game.push(senate[i]);
if(senate[i] == 'R') RCount++;
else DCount++;
}
int popRCount = 0;
int popDCount = 0;
while(!game.empty()){
if(RCount == 0) return "Dire";
if(DCount == 0) return "Radiant";
char cur = game.front();
game.pop();
if(cur == 'R'){
if(popRCount > 0){
popRCount--;
RCount--;
continue;
}
popDCount++;
game.push(cur);
}
if(cur == 'D'){
if(popDCount > 0){
popDCount--;
DCount--;
continue;
}
popRCount++;
game.push(cur);
}
}
return "";
}
};