Advertisement
1784. Check if Binary String Has at Most One Segment of Ones
UnknownView on LeetCode
Time: O(n)
Space: O(1)
Approach
A second segment of ones is indicated by '01'; return !s.Contains("01").
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");
}
}Advertisement
Was this solution helpful?