-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4 May | 649. Dota2 Senate.cpp
42 lines (40 loc) · 1.15 KB
/
4 May | 649. Dota2 Senate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Solution {
public:
void ban(string senate, vector<bool>&banned, char toBan, int startAt){
while(true){
if(senate[startAt] == toBan && !banned[startAt]){
banned[startAt] = true;
break;
}
startAt = (startAt + 1) % senate.size();
}
}
string predictPartyVictory(string senate) {
int n = senate.size();
vector<bool> banned(n,false);
int rCount = 0, dCount = 0;
for(int i = 0; i < n; i++){
if(senate[i] == 'R'){
rCount++;
}
else{
dCount++;
}
}
int i = 0;
while(rCount > 0 && dCount > 0){
if(!banned[i]){
if(senate[i] == 'R'){
ban(senate, banned, 'D', (i+1) % senate.size());
dCount--;
}
else{
ban(senate, banned, 'R', (i+1) % senate.size());
rCount--;
}
}
i = (i+1) % senate.size();
}
return rCount == 0 ? "Dire" : "Radiant";
}
};