class Solution:
def isPalindrome(self, x: int) -> bool:
s = str(x)
return s == s[::-1]Where is the number of digits in the given integer.
class Solution:
def isPalindrome(self, x: int) -> bool:
s = str(x)
n = len(s)
for i in range(n // 2):
if s[i] != s[n - i - 1]:
return False
return TrueWhere is the number of digits in the given integer.
class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0:
return False
rev = 0
num = x
while num:
rev = (rev * 10) + (num % 10)
num //= 10
return rev == xWhere is the number of digits in the given integer.
class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0:
return False
div = 1
while x >= 10 * div:
div *= 10
while x:
if x // div != x % 10:
return False
x = (x % div) // 10
div //= 100
return TrueWhere is the number of digits in the given integer.
class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0 or (x != 0 and x % 10 == 0):
return False
rev = 0
while x > rev:
rev = (rev * 10) + (x % 10)
x //= 10
return x == rev or x == rev // 10Where is the number of digits in the given integer.