-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
/
Copy pathSolution.rs
30 lines (29 loc) · 911 Bytes
/
Solution.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
impl Solution {
pub fn predict_party_victory(senate: String) -> String {
let mut qr = std::collections::VecDeque::new();
let mut qd = std::collections::VecDeque::new();
let n = senate.len();
for i in 0..n {
if let Some(char) = senate.chars().nth(i) {
if char == 'R' {
qr.push_back(i);
} else {
qd.push_back(i);
}
}
}
while !qr.is_empty() && !qd.is_empty() {
let front_qr = qr.pop_front().unwrap();
let front_qd = qd.pop_front().unwrap();
if front_qr < front_qd {
qr.push_back(front_qr + n);
} else {
qd.push_back(front_qd + n);
}
}
if qr.is_empty() {
return "Dire".to_string();
}
"Radiant".to_string()
}
}