Check Binary String for One Segment of Ones

Day 65: The "One-Liner" Win 🎯 Problem 1784: Check if Binary String Has at Most One Segment of Ones Today was a lesson in simplifying logic. The challenge: check if a binary string contains more than one contiguous segment of '1's, given that the string starts with '1'. The Strategy: • Observation: If there are multiple segments of '1's, they must be separated by at least one '0'. • The Pattern: In a string starting with '1', any "new" segment of ones would look like "01" somewhere in the string. • The Execution: A simple !s.contains("01") handles the entire check. Sometimes we hunt for complex algorithms when a single string method is the ultimate counter. Clean, readable, and passed all test cases. 🚀 #LeetCode #Java #StringManipulation #Coding #Efficiency #DailyCode

  • text

To view or add a comment, sign in

Explore content categories