Just a Python version of this brilliant C++ solution.
def isPalindrome(self, x): if x < 0 or (x > 0 and x % 10 == 0): return False half = 0 while x > half: half, x = half * 10 + x % 10, x / 10 return x in (half, half / 10)
How about manual int(str(x)[::-1])?
def isPalindrome(self, x): y,t = 0,abs(x) while t: y = y*10 + t%10 t //= 10 return x == y
"You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case?"
So the solution is prone to overflow problem, however this is not an issue in python as it handles large values gracefully.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.