Use the method in Manacher Algorithm which add '#' character in the string to handle both of odd and even lengths .
class Solution: # @return a boolean def isPalindrome(self, x): s = str(x).strip() T = '#' for i in range(0,len(s)): T += s[i] + '#' n = len(T)/2 -1 p = len(T)/2 +1 while n != 0: if T[n] == T[p]: n -=1 p +=1 else: return False return True
Though the judge accepts this solution - Note the restriction on not using extra space . Well , I made a very similar mistake of casting the int to a string and using the addressability of the string. I guess the point of this exercise is to find if they are a palindrome without exploiting the addressability of a string.