有点循环队列的意思(看题解写的)
class Solution {
public:
string predictPartyVictory(string senate) {
int l=senate.length();
queue<int>R;
queue<int>D;
int i=0;
while(i<l)
{
if(senate[i]=='R')
R.push(i);
if(senate[i]=='D')
D.push(i);
i++;
}
while(!R.empty()&&!D.empty())
{
int r=R.front();
int d=D.front();
if(R.front()<D.front())
{
D.pop();
R.pop();
R.push(r+l);
}
else
{
R.pop();
D.pop();
D.push(d+l);
}
}
return R.empty()?"Dire":"Radiant";
}
};