Beat 88% Python solutions


  • 0
    T
    class Solution(object):
        def isPalindrome(self, x):
            """
            :type x: int
            :rtype: bool
            """
            if x < 0:
                return False
            num = str(x)
            head,tail = 0,len(num)-1
            while (tail-head) > 1:
                if num[head] != num[tail]:
                    break
                head,tail = head+1,tail-1
            if (tail-head) > 1:
                return False
            else:
                if num[tail] == num[head]:
                    return True
                else:
                    return False

Log in to reply
 

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