-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdota2-senate.rs
56 lines (49 loc) · 1.38 KB
/
dota2-senate.rs
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
48
49
50
51
52
53
54
55
56
#![allow(dead_code, unused, unused_variables)]
fn main() {
assert_eq!(
"Dire".to_string(),
Solution::predict_party_victory("DDRRR".to_string())
);
}
struct Solution;
impl Solution {
pub fn predict_party_victory(senate: String) -> String {
let mut senate = senate
.as_bytes()
.into_iter()
.map(|x| *x)
.collect::<Vec<u8>>();
let (mut r_ban, mut d_ban) = (0, 0);
loop {
let (mut r_num, mut d_num) = (0, 0);
for i in 0..senate.len() {
if senate[i] == b'x' {
continue;
}
if senate[i] == b'R' {
if r_ban > 0 {
r_ban -= 1;
senate[i] = b'x';
} else {
d_ban += 1;
r_num += 1;
}
} else {
if d_ban > 0 {
d_ban -= 1;
senate[i] = b'x';
} else {
r_ban += 1;
d_num += 1;
}
}
}
if r_num == 0 {
return "Dire".to_string();
}
if d_num == 0 {
return "Radiant".to_string();
}
}
}
}