1784. Check if Binary String Has at Most One Segment of Ones Easy
1/**
2 * [1784] Check if Binary String Has at Most One Segment of Ones
3 *
4 * Given a binary string s without leading zeros, return true if s contains at most one contiguous segment of ones. Otherwise, return false.
5 *
6 * Example 1:
7 *
8 * Input: s = "1001"
9 * Output: false
10 * Explanation: The ones do not form a contiguous segment.
11 *
12 * Example 2:
13 *
14 * Input: s = "110"
15 * Output: true
16 *
17 * Constraints:
18 *
19 * 1 <= s.length <= 100
20 * s[i] is either '0' or '1'.
21 * s[0] is '1'.
22 *
23 */
24pub struct Solution {}
25
26// problem: https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones/
27// discuss: https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones/discuss/?currentPage=1&orderBy=most_votes&query=
28
29// submission codes start here
30
31impl Solution {
32 pub fn check_ones_segment(s: String) -> bool {
33 false
34 }
35}
36
37// submission codes end
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42
43 #[test]
44 fn test_1784() {
45 }
46}
47
Back
© 2025 bowen.ge All Rights Reserved.