-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path649.cpp
More file actions
26 lines (26 loc) · 744 Bytes
/
Copy path649.cpp
File metadata and controls
26 lines (26 loc) · 744 Bytes
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
class Solution {
public:
string predictPartyVictory(string senate) {
int R = 1, D = 1, r = 0, d = 0;
while (R > 0 && D > 0) {
R = 0, D = 0;
for (int i = 0; i < senate.size(); ++i) {
char &c = senate[i];
if (c == '_')
continue;
if (c == 'R') {
if (d > 0)
c = '_', --d;
else
++r, ++R;
} else if (c == 'D') {
if (r > 0)
c = '_', --r;
else
++d, ++D;
}
}
}
return R > 0 ? "Radiant" : "Dire";
}
};