leetcode problem palindromic sequence, sequence determination palindromic

Solution a: converted to a string, then the string before and after comparison.

class Solution:
    def isPalindrome(self, x: int) -> bool:
        if x < 0:
            return False #发现负数不可能是回文串,所以在这里直接判断
        x = str(abs(x)) #这里可以去掉绝对值,因为不可能是负数
        if len(x) == 1:
            return True
        for i in range((len(x)+1)//2): #判断前半部分就够了
            if x[i] != x[len(x)-1-i]:
                return False
        return True

Solution two: official solution to a problem, not into a string.

I think the solution to a problem, there are two places you can learn from, a part of the data overflow attention, on the other hand it is to determine whether to process half of the integers, take a half a reference significance for other similar integers.

Also attached python obtained 32int minimum maximum method.

Published 39 original articles · won praise 2 · views 10000 +

Guess you like

Origin blog.csdn.net/m0_37962192/article/details/104352886