-
Notifications
You must be signed in to change notification settings - Fork 13
/
Solution649.java
37 lines (31 loc) · 892 Bytes
/
Solution649.java
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
package algorithm.leetcode;
import java.util.ArrayDeque;
/**
* @author Administrator
* @desc Dota2 参议院
* @create 2019/01/22
*/
public class Solution649 {
public String predictPartyVictory(String senate) {
ArrayDeque<Integer> r = new ArrayDeque<>();
ArrayDeque<Integer> d = new ArrayDeque<>();
for (int i = 0; i < senate.length(); ++i) {
if ('R' == senate.charAt(i)) {
r.add(i);
} else {
d.add(i);
}
}
int n = senate.length();
while (!r.isEmpty() && !d.isEmpty()) {
int r_id = r.pollFirst();
int d_id = d.pollFirst();
if (r_id < d_id) {
r.addLast(r_id + n);
} else {
d.addLast(d_id + n);
}
}
return r.size() > d.size() ? "Radiant" : "Dire";
}
}