Python 4-line, 40ms


  • -2
    P

    As long as the first half is mirrored in the second half of the integer.

    class Solution(object):
        def isPalindrome(self, x):
            for i in xrange(len(str(x))//2):
                if str(x)[i] != str(x)[len(str(x)) - i - 1]:
                    return False
            return True

  • 3
    T

    Hi,
    str(x) creates a string of the number x, so your method do uses extra space.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.