-
Notifications
You must be signed in to change notification settings - Fork 0
/
28. 649. Dota2 Senate
40 lines (35 loc) · 969 Bytes
/
28. 649. Dota2 Senate
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Solution {
public String predictPartyVictory(String senate) {
int rCount =0,rBan=0,dCount=0,dBan=0;
Queue<Character> q = new LinkedList<Character>();
for(int i=0;i<senate.length();i++){
q.add(senate.charAt(i));
if(senate.charAt(i)=='R'){
rCount++;
}else{
dCount++;
}
}
while(dCount>0 && rCount>0){
char ch = q.remove();
if(ch=='R'){
if(rBan>0){
rBan--;
rCount--;
}else{
dBan++;
q.add(ch);
}
}else{
if(dBan>0){
dBan--;
dCount--;
}else{
rBan++;
q.add(ch);
}
}
}
return rCount>0 ? "Radiant" : "Dire";
}
}