In this example, We have shared how to find palindrome Number in Python. If the string and reversed string are the same, then the number is a palindrome. So return true in that case, otherwise, return false.
Here is an example:
1 2 3 4 5 6 7 8 | class Solution(object): def isPalindrome(self, x): """ :type x: int :rtype: bool """ val = str(x) return val == val[::-1] |
Input
1 2 | 424 -565 |
Output
1 2 | true false |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.