In the Leetcode Palindrome Number problem solution in Python programming Given an integer x, return true if x is a palindrome, and false otherwise.
Leetcode Palindrome Number problem solution in Python programming
import math
class Solution(object):
def isPalindrome(self, x):
if x < 0:
return False
digits = 1
while x // digits >= 10:
digits *= 10
while x > 0:
last = x % 10
first = x // digits
if last != first:
return False
x %= digits
x //= 10
digits //= 100
return True
Also read,
- Leetcode Palindrome Number problem solution in C++
- Leetcode Palindrome Number problem solution in Java
- Leetcode Palindrome Number problem solution in C
- Leetcode Palindrome Number problem solution in C#