第六十五天:力扣649题,Dota2 参议院
地址:leetcode-cn.com/problems/do…
思路:栈+队列即可。
var predictPartyVictory = function(senate) {
let res = senate.split("");
let stack = [];
while(res[0])
{
let a = res.shift();
if(stack.length === 0 || stack[stack.length - 1] === a)
{
stack.push(a);
}
else
{
res.push(stack.pop());
}
}
return stack.pop() === 'R' ? 'Radiant' : 'Dire';
};
执行用时:104 ms, 在所有 JavaScript 提交中击败了50.00%的用户
内存消耗:42.1 MB, 在所有 JavaScript 提交中击败了12.50%的用户