class Solution: # @return a boolean def isPalindrome(self, x): if x < 0: return False z = x s = 0 while z: s = s*10 + z%10 z //= 10 return s==x
It can be accepted by C++, but TLE in Python. So has anyone succeeded in Python? Thanks.
I tried your way and another method that converts integer to string. Result is not always TLE.
While the ratio is one AC with 5 TLE.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.