Archieve/알고리즘
[Leetcode] 649. Dota2 Senate
mydailylogs
2023. 5. 5. 01:38
class Solution:
def predictPartyVictory(self, senate: str) -> str:
A = collections.deque()
people = [0, 0]
bans = [0, 0]
for person in senate:
x = person == 'R'
people[x] += 1
A.append(x)
while all(people):
x = A.popleft()
people[x] -= 1
if bans[x]:
bans[x] -= 1
else:
people[x] +=1
bans[x^1] += 1
A.append(x)
return 'Radiant' if people[1] else 'Dire'