9 | Palindrome Number | 35.70% | 检查是不是回文数字,先反转之后判断再判断是否相等 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 3 18:52:55 2018
@author: vicky
"""
class Solution:
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
# if x>=0:
# x2=int(str(x)[::-1])
# else:
# x2=-int(str(-x)[::-1])
# if x2==x and x>=0:
# return(True)
# else:
# return(False)
x2=int(str(x)[::-1]) if x>=0 else -int(str(-x)[::-1])
return True if x2==x and x>=0 else False
x=1
t=Solution()
t.isPalindrome(x)
class Solution:
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
x3=abs(x)
x4=0
while x3>0:
x4=10*x4+x3%10
x3=int(x3/10)
return True if x==x4 else False