您的位置:首页 > 其它

【leetcode题解】【28】【E】Palindrome Number

2015-12-06 21:25 387 查看
class Solution(object):
def isPalindrome(self, x):

l = 1
if x < 0 :
return False
#x = 0 - x
while x / (pow(10,l)):
l += 1
#print l

a = 1
b = pow(10,l-1)

for i in range(0,l/2):
#print i,l-i-1
if x/a%10 == x/b%10:
a *= 10
b /= 10
continue
else:
return False
return True
"""
:type x: int
:rtype: bool
"""


Determine whether an integer is a palindrome. Do this without extra space.

click to show spoilers.

Subscribe to see which companies asked this question
求一个数字是不是回文,
采用求幂和取余,按位比较
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: