美文网首页
[LeetCode By Python] 9. Palindro

[LeetCode By Python] 9. Palindro

作者: 乐乐可爱睡觉 | 来源:发表于2016-06-21 09:26 被阅读137次

一、题目

Palindrome Number

二、解题

判断一个数字是否是回文串。

左边:使用字符串来操作
右边:使用数字来操作

感觉这题怎么样都可以实现。

三、尝试与结果

class Solution(object):
    def isPalindrome(self, x):
        if x < 0 :
            return False
        i = 0
        while i < len(str(x))/2:
            left = str(x)[i]
            right = x/(10 ** i) % 10
            if int(left) != right:
                return False
            i = i + 1
        return True

结果:AC

相关文章

网友评论

      本文标题:[LeetCode By Python] 9. Palindro

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