cs: add «649. Dota2 Senate»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-08-10 00:31:04 +02:00
parent c272832714
commit e65bafabca
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

27
cs/dota2-senate.cs Normal file
View 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";
}
}