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.
- String slicing in Python to check if a string can become empty by recursive deletion
- Python | Check if given string can be formed by concatenating string elements of list
- Python | Check if string ends with any string in given list
- Periodic Binary String With Minimum Period and a Given Binary String as Subsequence.
- Check if all the 1's in a binary string are equidistant or not
- Check divisibility of binary string by 2^k
- Check if a binary string contains consecutive same or not
- Check if a binary string has a 0 between 1s or not | Set 1 (General approach)
- Check if it is possible to rearrange a binary string with alternate 0s and 1s
- Check if a binary string contains all permutations of length k
- Check if a binary string has two consecutive occurrences of one everywhere
- Check if an encoding represents a unique binary string
- Check whether the binary equivalent of a number ends with given string or not
- Check if a binary string has a 0 between 1s or not | Set 2 (Regular Expression Approach)
- Check whether a binary string can be formed by concatenating given N numbers sequentially
- String obtained by reversing and complementing a Binary string K times
- Longest sub string of 0's in a binary string which is repeated K times
- Convert binary to string using Python
- Python | Convert String to Binary
- Print string after removing all (“10” or “01”) from the binary string
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