leetcode python

来源:互联网 发布:big boss知乎 编辑:程序博客网 时间:2024/06/03 16:26
# Determine whether an integer is a palindrome.# Do this without extra space.class Solution(object):    def isPalindrome(self, x):        """        :type x: int        :rtype: bool        """        if x < 0 or x != 0 and x % 10 == 0:            return False        rev = 0        while x > rev:            rev = rev * 10 + x % 10            x /= 10        return x == rev or x == rev / 10


0 0
原创粉丝点击