美文网首页
3、回文数 leetcode9

3、回文数 leetcode9

作者: 九答 | 来源:发表于2020-04-01 12:09 被阅读0次

题目描述

description.png

思路:与数字反转思路一样,可直接解答

class Solution:
    def isPalindrome(self, x: int) -> bool:
        y = abs(x)
        nums = 0
        while (y!=0):
            num = y%10
            nums = nums*10 + num
            y = y//10
        if x == nums and x>=0:
            return True
        else:
            return False

相关文章

网友评论

      本文标题:3、回文数 leetcode9

      本文链接:https://www.haomeiwen.com/subject/rwmouhtx.html