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'
'CS > 알고리즘' 카테고리의 다른 글
[Leetcode] 1498. Number of Subsequences That Satisfy the Given Sum Condition (1) | 2023.05.06 |
---|---|
[Leetcode] 1456. Maximum Number of Vowels in a Substring of Given Length (0) | 2023.05.06 |
[Leetcode] 986. Interval List Intersections (0) | 2023.05.05 |
[Leetcode] 844. Backspace String Compare (0) | 2023.05.05 |
[Leetcode] 82. Remove Duplicates from Sorted List II (0) | 2023.05.04 |