LeetCode Entry

1784. Check if Binary String Has at Most One Segment of Ones

06.03.2026 easy 2026 kotlin rust

+0 pattern

1784. Check if Binary String Has at Most One Segment of Ones easy blog post substack youtube

ccfe0859-5820-4dff-8521-1e41fe93539e (1).webp

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/1289

Problem TLDR

1+0* pattern #easy

Intuition

  1. Regex ^1+0*$

Approach

  • or just check of 01

Complexity

  • Time complexity: \(O(n)\)

  • Space complexity: \(O(1)\)

Code

// 7ms
    fun checkOnesSegment(s: String) =
    "01" !in s
// 0ms
    pub fn check_ones_segment(s: String) -> bool {
        !s.contains("01")
    }