LeetCode/Python: 9. Palindrome Number

class Solution():
    # @return a boolean
    def isPalindrome(self, x):
        if x < 0:
            return False
        div = 1
        while x/div >= 10:
            div = div * 10
            
        while x:
            left = int( x / div)
            right = int(x % 10)
            
            if left != right:
                return False
            
            x = int(( x % div ) / 10)
            div = div / 100
        return True
        
s = Solution()
print (s.isPalindrome(12321))

猜你喜欢

转载自www.cnblogs.com/lijinghuabj/p/9216208.html