题解 | #回文数字#

回文数字

http://www.nowcoder.com/practice/35b8166c135448c5a5ba2cff8d430c32

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param x int整型 
# @return bool布尔型
#
class Solution:
    def isPalindrome(self , x: int) -> bool:
        # write code here
        #不考虑空间复杂度
        if x < 0:
            return False
        nums = str(x)
        i = 0
        j = len(nums) - 1
        while i<j:
            if nums[i] != nums[j]:
                return False
            i += 1
            j -= 1
        return True
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务