cs: add «649. Dota2 Senate»
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
c272832714
commit
e65bafabca
1 changed files with 27 additions and 0 deletions
27
cs/dota2-senate.cs
Normal file
27
cs/dota2-senate.cs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
public class Solution {
|
||||||
|
public string PredictPartyVictory(string senate) {
|
||||||
|
var radiant = new Queue<int>();
|
||||||
|
var dire = new Queue<int>();
|
||||||
|
|
||||||
|
for (var i = 0; i < senate.Length; ++i) {
|
||||||
|
(senate[i] == 'R' ? radiant : dire).Enqueue(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (radiant.Count > 0 && dire.Count > 0) {
|
||||||
|
var r = radiant.Dequeue();
|
||||||
|
var d = dire.Dequeue();
|
||||||
|
|
||||||
|
if (r < d) {
|
||||||
|
radiant.Enqueue(senate.Length + r);
|
||||||
|
} else {
|
||||||
|
dire.Enqueue(senate.Length + d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (radiant.Count > 0) {
|
||||||
|
return "Radiant";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Dire";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue