美文网首页Leetcode
Leetcode 649. Dota2 Senate

Leetcode 649. Dota2 Senate

作者: SnailTyan | 来源:发表于2021-07-21 15:11 被阅读0次

    文章作者:Tyan
    博客:noahsnail.com  |  CSDN  |  简书

    1. Description

    Dota2 Senate

    2. Solution

    解析:Version 1每次投票都禁掉一个对方的参议员,由于是循环投票,因此当前投票的参议员在投票结束后进入队尾,投票直至分出胜负,即只剩下一方的参议员为止。

    • Version 1
    class Solution:
        def predictPartyVictory(self, senate: str) -> str:
            while 'R' in senate and 'D' in senate:
                if senate[0] == 'R':
                    senate = senate[1:].replace('D', '', 1) + senate[0]
                else:
                    senate = senate[1:].replace('R', '', 1) + senate[0]
            if senate[0] == 'R':
                return 'Radiant'
            else:
                return 'Dire'
    

    Reference

    1. https://leetcode.com/problems/dota2-senate/

    相关文章

      网友评论

        本文标题:Leetcode 649. Dota2 Senate

        本文链接:https://www.haomeiwen.com/subject/zksiultx.html