Discuss / Python / 数学方法

数学方法

Topic source

陌然

#1 Created at ... [Delete] [Delete and Lock User]

都是转换为字符串的方法,难道就我一个写这种不转换的方法吗

def is_palindrome(n):
    cnt = len(str(n))
    i = cnt
    while i > 1:
        if (int)( n/(10**(i-1))%10 ) != (int)( n%(10**(cnt-i+1))/(10**(cnt-i)) ):
            return False
        i = i - 1
    return True

转换成字符的方法我也写了,确实不用想那么复杂。

陌然

#2 Created at ... [Delete] [Delete and Lock User]

以前只会C语言,Python是第一次学


  • 1

Reply