Check if Binary Representation is Palindrome
EasyPractice library · +10 XPbit manipulationstrings
Given a single non-negative integer N, determine if its binary representation is a palindrome. A binary representation is a palindrome if it reads the same forwards and backwards. For example, the binary representation of 9 is 1001, which is a palindrome. The binary representation of 5 is 101, which is also a palindrome. The binary representation of 6 is 110, which is not a palindrome.
Input
A single line containing the integer N.
Output
Print 'Yes' if the binary representation of N is a palindrome, and 'No' otherwise.
Constraints
0 <= N <= 10^9
Time limit 1 s (native code; slower languages get more)Memory 256 MB14 hidden tests
Example 1
Input
9
Output
Yes
Binary of 9 is 1001, which is a palindrome.
Example 2
Input
6
Output
No
Binary of 6 is 110, which is not a palindrome.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
9
Example 2 input
6