mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 01:49:41 +01:00
28 lines
685 B
C#
28 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";
|
||
|
}
|
||
|
}
|