1869. Longer Contiguous Segments of Ones than Zeros Easy
1/**
2 * [1869] Longer Contiguous Segments of Ones than Zeros
3 *
4 * 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.
5 *
6 * For example, in s = "<u>11</u>01<u>000</u>10" the longest continuous segment of 1s has length 2, and the longest continuous segment of 0s has length 3.
7 *
8 * Note that if there are no 0's, then the longest continuous segment of 0's is considered to have a length 0. The same applies if there is no 1's.
9 *
10 * Example 1:
11 *
12 * Input: s = "1101"
13 * Output: true
14 * Explanation:
15 * The longest contiguous segment of 1s has length 2: "<u>11</u>01"
16 * The longest contiguous segment of 0s has length 1: "11<u>0</u>1"
17 * The segment of 1s is longer, so return true.
18 *
19 * Example 2:
20 *
21 * Input: s = "111000"
22 * Output: false
23 * Explanation:
24 * The longest contiguous segment of 1s has length 3: "<u>111</u>000"
25 * The longest contiguous segment of 0s has length 3: "111<u>000</u>"
26 * The segment of 1s is not longer, so return false.
27 *
28 * Example 3:
29 *
30 * Input: s = "110100010"
31 * Output: false
32 * Explanation:
33 * The longest contiguous segment of 1s has length 2: "<u>11</u>0100010"
34 * The longest contiguous segment of 0s has length 3: "1101<u>000</u>10"
35 * The segment of 1s is not longer, so return false.
36 *
37 *
38 * Constraints:
39 *
40 * 1 <= s.length <= 100
41 * s[i] is either '0' or '1'.
42 *
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros/
47// discuss: https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52 pub fn check_zero_ones(s: String) -> bool {
53 false
54 }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_1869() {
65 }
66}
67
Back
© 2025 bowen.ge All Rights Reserved.