-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdota2Senate.cpp
More file actions
28 lines (27 loc) · 777 Bytes
/
dota2Senate.cpp
File metadata and controls
28 lines (27 loc) · 777 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
27
28
// Source: https://leetcode.com/problems/dota2-senate/
// Author: Miao Zhang
// Date: 2021-02-26
class Solution {
public:
string predictPartyVictory(string senate) {
int n = senate.size();
queue<int> radiant, dire;
for (int i = 0; i < n; i++) {
if (senate[i] == 'R') {
radiant.push(i);
} else {
dire.push(i);
}
}
while (!radiant.empty() && !dire.empty()) {
if (radiant.front() < dire.front()) {
radiant.push(radiant.front() + n);
} else {
dire.push(dire.front() + n);
}
radiant.pop();
dire.pop();
}
return !radiant.empty() ? "Radiant" : "Dire";
}
};