10 leetcode - Palindrome Number

    xiaoxiao2021-12-12  2

    注意:在leetcode中负数都不是回文数字.

    #!/usr/bin/python # -*- coding: utf-8 -*- ''' 英文:Determine whether an integer is a palindrome. Do this without extra space. 中文:判断一个数是不是回文数字 举例:12345 不是 12321 是,注意:leetcode中负数都不是回文数字 ''' class Solution(object): '''将数字翻转后,判断两个数字是否相等''' def isPalindrome(self, x): """ :type x: int :rtype: bool """ if x < 0: return False m = x n = 0 while x: n = n * 10 + x % 10 x = x/10 return True if m == n else False if __name__ == "__main__": s = Solution() print s.isPalindrome()
    转载请注明原文地址: https://ju.6miu.com/read-900274.html

    最新回复(0)