1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/cs/dota2-senate.cs
Matej Focko e65bafabca
cs: add «649. Dota2 Senate»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-08-10 00:31:04 +02:00

27 lines
685 B
C#

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