题解 | 参议院投票
参议院投票
https://www.nowcoder.com/practice/f334a81b22654efc8d7a67e31f60de50
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 求出最终获胜帮派的名称 # @param s string字符串 # @return string字符串 # class Solution: def predictVictory(self , s: str) -> str: # write code here red_stack = [] dark_stack = [] for i,char in enumerate(s): if char == "R": red_stack.append(i) else: dark_stack.append(i) while red_stack and dark_stack: red_index = red_stack.pop(0) dark_index = dark_stack.pop(0) if red_index < dark_index: red_stack.append(red_index + len(s)) else: dark_stack.append(dark_index + len(s)) return "Red" if red_stack else "Dark"