LeetCode Entry
1784. Check if Binary String Has at Most One Segment of Ones
+0 pattern
1784. Check if Binary String Has at Most One Segment of Ones easy blog post substack youtube

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/1289
Problem TLDR
1+0* pattern #easy
Intuition
- 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")
}