LeetCode Easy: Palindrome Number

一、题目

Determine whether an integer is a palindrome. Do this without extra space.

二、解题思路

首先我想到的是把给定的数变成字符串,通过字符串反转判断是否相等来判断原数是不是回文数。首先要判断给定的数是不是负数,负数肯定不是回文数。

三、代码

class Solution:
    def isPalindrome(self, x):
        """
        :type x: int
        :rtype: bool
        """
        if x<0:
            return False
        else:
            fx = float(str(x)[::-1])
            if fx == x:
                return True
            else:
                return False

  

既然无论如何时间都会过去,为什么不选择做些有意义的事情呢
原文地址:https://www.cnblogs.com/xiaodongsuibi/p/8587601.html