-
Notifications
You must be signed in to change notification settings - Fork 0
/
p1869.rs
32 lines (29 loc) · 822 Bytes
/
p1869.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
#[test]
fn test() {
assert_eq!(check_zero_ones("1101".to_string()), true);
assert_eq!(check_zero_ones("111000".to_string()), false);
assert_eq!(check_zero_ones("110100010".to_string()), false);
assert_eq!(check_zero_ones("01111110".to_string()), true);
}
pub fn check_zero_ones(s: String) -> bool {
let mut cnt0: i32 = 0;
let mut cnt1: i32 = 0;
let mut max_cnt0: i32 = 0;
let mut max_cnt1: i32 = 0;
for c in s.chars() {
match c {
'0' => {
cnt1 = 0;
cnt0 += 1;
max_cnt0 = max_cnt0.max(cnt0);
}
'1' => {
cnt0 = 0;
cnt1 += 1;
max_cnt1 = max_cnt1.max(cnt1);
}
_ => unreachable!(),
}
}
max_cnt1 > max_cnt0
}