美文网首页
2019-05-149. LeetCode回文数

2019-05-149. LeetCode回文数

作者: mztkenan | 来源:发表于2019-05-14 11:02 被阅读0次

10分钟,参见整数反转的思想,这里不用担心反转后时候越界

class Solution:
    def isPalindrome(self, x: int) -> bool:
        if x<0:return False
        tmp=0
        x_=x
        while(x_>0):
            tmp=10*tmp+x_%10
            x_=x_//10
        if tmp==x:return True # 想不通,光字面意思是想不通,哦,x变了
        else:return False

1.题目理解不透彻,小于0的不能算做回文数
2.reult==x,总是不对,想不通,原来是x已经在过程中改了,所以要保存原来的值。这里想不通的时候,换一方向

相关文章

网友评论

      本文标题:2019-05-149. LeetCode回文数

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