-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path649-Dota2-Senate.cpp
More file actions
47 lines (44 loc) · 1.27 KB
/
649-Dota2-Senate.cpp
File metadata and controls
47 lines (44 loc) · 1.27 KB
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
41
42
43
44
45
46
47
class Solution {
public:
string predictPartyVictory(string s) {
queue<int> q;
queue<int> r;
queue<int> d;
for(int i=0 ; i<s.size() ;i++){
q.push(i);
if(s[i] == 'R') r.push(i);
else d.push(i);
}
while(q.size()>1){
if(s[q.front()] == 'X') q.pop();
else if(s[q.front()] == 'R'){
// check for victory
if(d.size()==0) return \Radiant\;
// take rights of D
else{
s[d.front()] = 'X';
d.pop();
q.push(q.front());
q.pop();
r.push(r.front());
r.pop();
}
}
else{// D
// check for victory
if(r.size()==0) return \Dire\;
// take rights of D
else{
s[r.front()] = 'X';
r.pop();
q.push(q.front());
q.pop();
d.push(d.front());
d.pop();
}
}
}
if(s[q.front()]== 'R') return \Radiant\;
else return \Dire\;
}
};