forked from AnasImloul/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDota2 Senate.py
25 lines (25 loc) · 819 Bytes
/
Dota2 Senate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Runtime: 162 ms (Top 30.92%) | Memory: 14.2 MB (Top 58.94%)
class Solution:
def predictPartyVictory(self, senate: str) -> str:
nxt = ""
ar, de = senate.count('R'), senate.count('D')
r , d = 0, 0
while(ar and de) :
for i in senate :
if (i== 'R' and d == 0):
r += 1
nxt = nxt + 'R'
elif (i== 'R' and d > 0):
d -= 1
elif (i== 'D' and r > 0):
r -= 1
elif(i== 'D' and r == 0):
d += 1
nxt = nxt + 'D'
senate = nxt
nxt = ""
ar, de = senate.count('R'), senate.count('D')
if (ar) :
return 'Radiant'
else:
return 'Dire'