0
点赞
收藏
分享

微信扫一扫

leetcode -- Palindrome Number

ivy吖 2023-06-29 阅读 48


https://leetcode.com/problems/palindrome-number/

understanding:


题目原意是要我们用数学的办法去coding,而不是转化成string。但转化成string也可以通过。


my code:


class Solution(object):
    def isPalindrome(self, x):
        """
        :type x: int
        :rtype: bool
        """
        if x >=0:
            x = str(x)
        else:
            return False
        i = 0
        j = len(x) - 1
        
        while j > i:
            
            if x[i] == x[j]:
                i += 1
                j -= 1
            else:
                break
        if j <= i:
            return True
        else:
            return False


举报

相关推荐

0 条评论