原题题目
代码实现(首刷自解)
class Solution {
public:string predictPartyVictory(string senate) {
int n = senate.size(),r = 0,d = 0,fr = 0,fd = 0,dr = 0,dd = 0;vector<bool> visit(senate.size(),false);for(int i=0;i<n;++i){
if(senate[i] == 'R') ++r;else ++d;}while(1){
for(int i=0;i<n;++i){
if(visit[i]) continue;if(dr == r) return "Dire";if(dd == d) return "Radiant";if(senate[i] == 'R'){
if(fr < dr){
visit[i] = true;++fr;continue;}++dd;}else{
if(fd < dd){
visit[i] = true;++fd;continue;}++dr;}if(dr == r) return "Dire";if(dd == d) return "Radiant";}}return "";}
};