【Leetcode】【Python】9. Palindrome Number实现

来源:互联网 发布:傅园慧表情包刷爆网络 编辑:程序博客网 时间:2024/05/09 10:18

题目:

Determine whether an integer is a palindrome. Do this without extra space.

click to show spoilers.

Subscribe to see which companies asked this question.

思路:

将数字转化为字符串,头尾相互开始比较,直到结束或者匹配不成功。


实现:

class Solution(object):    def isPalindrome(self, x):        """        :type x: int        :rtype: bool        """        if x<0:            return False        x=str(x)        for i in range(len(x)//2):            if x[i]!=x[len(x)-i+1]:                return False        return True

0 0
原创粉丝点击