LeetCode1.4

作者: supermanwasd | 来源:发表于2019-01-04 22:51 被阅读0次

    Palindrome Number

    Screen Shot 2019-01-04 at 10.48.41 PM.png

    答案:

    class Solution:
        def isPalindrome(self, x):
            """
            :type x: int
            :rtype: bool
            """
            orig = x
            rev = 0
            if x >= 0:
                while x > 0:
                    dig = x % 10
                    rev = rev * 10 + dig
                    x = x // 10
                if rev == orig:
                    return True 
                else:
                    return False
            else: 
                return False

    相关文章

      网友评论

        本文标题:LeetCode1.4

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