Dota2 Senate LeetCode solution in C++

1
class Solution {
2
public:
3
string predictPartyVictory(string senate) {
4
queue<int> D, R;
5
int len = senate.size();
6
for (int i = 0; i < len; i++) {
7
if (senate[i] == 'D') {
8
D.push(i);
9
} else {
10
R.push(i);
11
}
12
}
13

14
while (!D.empty() && !R.empty()) {
15
int dIdx = D.front();
16
D.pop();
17

18
int rIdx = R.front();
19
R.pop();
20

21
if (dIdx < rIdx) {
22
D.push(dIdx + len);
23
} else {
24
R.push(rIdx + len);
25
}
26
}
27

28
return D.empty() ? "Radiant" : "Dire";
29
}
30
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0