1784. Check if Binary String Has at Most One Segment of Ones ¶ Time: $O(n)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6class Solution { public: bool checkOnesSegment(string s) { return s.find("01") == string::npos; } }; 1 2 3 4 5class Solution { public boolean checkOnesSegment(String s) { return !s.contains("01"); } } 1 2 3class Solution: def checkOnesSegment(self, s: str) -> bool: return '01' not in s