leetcode:Palindrome Number【Python版】

it2022-05-19  65

一次AC

题目要求中有空间限制,因此没有采用字符串由量变向中间逐个对比的方法,而是采用计算翻转之后的数字与x是否相等的方法;

1 class Solution: 2 # @return a boolean 3 def isPalindrome(self, x): 4 o = x 5 ret = 0 6 flag = 1 7 if x < 0: 8 return False 9 while(x!=0): 10 ret = ret*10+x 11 x = x/10 12 return ret == o

 

转载于:https://www.cnblogs.com/CheeseZH/p/4033974.html

相关资源:数据结构—成绩单生成器

最新回复(0)