We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 019d563 commit 39518edCopy full SHA for 39518ed
1 file changed
C++/dota2-senate.cpp
@@ -0,0 +1,19 @@
1
+// Time: O(n)
2
+// Space: O(n)
3
+
4
+class Solution {
5
+public:
6
+ string predictPartyVictory(string senate) {
7
+ queue<int> radiant, dire;
8
+ const auto& n = senate.length();
9
+ for (int i = 0; i < n; ++i) {
10
+ (senate[i] == 'R') ? radiant.emplace(i) : dire.emplace(i);
11
+ }
12
+ while (!radiant.empty() && !dire.empty()) {
13
+ int r_idx = radiant.front(), d_idx = dire.front();
14
+ radiant.pop(), dire.pop();
15
+ (r_idx < d_idx) ? radiant.emplace(r_idx + n) : dire.emplace(d_idx + n);
16
17
+ return (radiant.size() > dire.size()) ? "Radiant" : "Dire";
18
19
+};
0 commit comments