#1869
Easy Algorithms Longer contiguous segments of ones than zeros
String
62.1% acceptance
Feb 25, 2026
561
13
Given a binary string s, return true if the longest contiguous segment of 1's is strictly longer than the longest contiguous segment of 0's in s, or return false otherwise.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn check_zero_ones(s: String) -> bool {
let max_run = |ch: u8| -> usize {
let mut max = 0;
let mut cur = 0;
for &b in s.as_bytes() {
if b == ch { cur += 1; max = max.max(cur); }
else { cur = 0; }
}
max
};
max_run(b'1') > max_run(b'0')
}
}