力扣 9. 回文数

题目来源:力扣 https://leetcode-cn.com/problemset/all/
力扣 9. 回文数_第1张图片

class Solution:
    def isPalindrome(x):
        '''
        #使用字符串翻转
        x = str(x)
        if x[::-1] == x:
            return True
        else:
            return False
        #使用正则表达式
        r = list(map(lambda i: int(10**-i * x % 10), range(int(math.log10(x)), -1, -1))) if x > 0 else [0, x]
        return r == r[::-1]
        '''
        if x < 0 or not x % 10 and x: 
            return False
        r = 0
        while x > r:
            x, rem = x // 10, x % 10
            r = r * 10 + rem
        return x == r or x == r // 10

正则表达式解法:https://leetcode-cn.com/problems/palindrome-number/solution/python-1xing-zi-fu-chuan-2xing-fei-zi-fu-chuan-by-/
半倒置解法:https://leetcode-cn.com/problems/palindrome-number/solution/palindrome-number-shu-zi-ban-dao-zhi-by-jyd/添加链接描述

你可能感兴趣的:(力扣算法题)