Discuss / Python / 提交练习

提交练习

Topic source

def is_palindrome(n): s=str(n) if s[0:]==s[::-1]: return n

迷龙丶

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

def is_palindrome(n): return str(n) == str(n)[::-1] 这样更简洁一些

李竹竿

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

这个虽然是方便,但是是不是要增加一倍的复杂度啊?

迷龙丶

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

不明白你说的复杂度是指什么,空间复杂度?时间复杂度? 我自己测试时这种方式比楼下的使用头尾比较的方式所用的时间更短,在range(1, 5000000)的范围内,这种方式用时4.1s,楼下的方式用时5.2秒,至于空间复杂度都是O(n)。


  • 1

Reply