Leetcode Palindrome Number Python Solution 判断回文数的python解法

二话不说,直接上代码:

  1 class Solution(object):
  2     def isPalindrome(self, x):
  3         """
  4         :type x: int
  5         :rtype: bool
  6         """
  7         x2 = str(x)
  8         if x2 == x2[::-1]:
  9             return True
 10         else:
 11             return False


一个比较精简的代码


image

运行时间打败了97%的代码

但是很占内存


image

猜你喜欢

转载自www.cnblogs.com/hungry5656/p/11222870.html
今日推荐