One Segment of Ones
s is a binary string that starts with 1. Return True if all the 1 characters form one single block (nothing but 0s may follow the block), or False if the ones are split into two or more blocks.
Example 1
s "1100"
returns true
One block of ones.
Example 2
s "110011"
returns false
Two separate blocks.
Constraints
1 <= len(s) <= 50shas0and1ands[0]is1
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Strings problems
- Percentage of Letter in StringBeginner
- Prefix of Any Word in a SentenceBeginner
- Remove Vowels from a StringBeginner
- Reverse Each WordBeginner
- Reverse Prefix of WordBeginner
- Reverse StringBeginner
- Snake Case to Camel CaseBeginner
- Stretch Each CharacterBeginner