DDSA Solutions

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

Time: O(n)
Space: O(1)

Problem Overview

Check if Binary String Has at Most One Segment of Ones (Unknown) asks you to solve a structured algorithmic task. This is a common String pattern in coding interviews. A second segment of ones is indicated by '01'; return !s.Contains("01").

A full step-by-step explanation is being added. See the study guide for pattern-based practice.

Approach

A second segment of ones is indicated by '01'; return !s.Contains("01").

Related patterns: String

1784.cs
C#
// Approach: A second segment of ones is indicated by '01'; return !s.Contains("01").
// Time: O(n) Space: O(1)

public class Solution
{
    public bool CheckOnesSegment(string s)
    {
        return !s.Contains("01");
    }
}
Was this solution helpful?

Related Problems