1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 01:36:57 +02:00

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";
}
}