Given a string str. The task is to check whether it is a binary string or not.
Input: str = "01010101010" Output: Yes Input: str = "geeks101" Output: No
Approach 1: Using Set
- Insert the given string in a set
- Check if the set characters consist of 1 and/or 0 only.
Approach 2: Simple Iteration
- Iterate for every character and check if the character is 0 or 1.
- If it is not then set a counter and break.
- After iteration check whether the counter is set or not.
- Check if given Binary string follows then given condition or not
- Check whether the binary equivalent of a number ends with given string or not
- Check if binary representations of 0 to N are present as substrings in given binary string
- Check if a binary string has a 0 between 1s or not | Set 1 (General approach)
- Check if a binary string has a 0 between 1s or not | Set 2 (Regular Expression Approach)
- Check if a binary string contains consecutive same or not
- Check if all the 1's in a binary string are equidistant or not
- Python Set | Check whether a given string is Heterogram or not
- Python program to check if a given string is Keyword or not
- Python | Check if given string is numeric or not
- Periodic Binary String With Minimum Period and a Given Binary String as Subsequence.
- Decimal representation of given binary string is divisible by 5 or not
- Program to check if a matrix is Binary matrix or not
- Check if a given string is Even-Odd Palindrome or not
- Check if the given string is linear or not
- Python | Check if a given object is list or not
- Python - Check whether the given List forms Contiguous Distinct Sub-Array or Not
- Python Membership and Identity Operators | in, not in, is, is not
- Python program to check if a string is palindrome or not
- Python program to check if string is empty or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nidhi_biet