题解 | 参议院投票

参议院投票

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"
            


全部评论

相关推荐

见见123:简历没有啥问题,是这个社会有问题。因为你刚毕业,没有工作经历,现在企业都不要没有工作经历的。社会病了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务