ほぼ日刊競プロ leetcode 9. Palindrome Number
9. Palindrome Number
Given an integer x, return true if x is palindrome integer.
An integer is a palindrome when it reads the same backward as forward.
・For example, 121 is a palindrome while 123 is not.
考えたこと
回文にすれば,良いのでfor文で一度intを文字列→リストに直して,逆さまにし元々の文字列と比較すれば良いと考えた.
class Solution:
def isPalindrome(self, x: int) -> bool:
temp =[]
for i in str(x):
#print (i)
temp.append(i)
temp=temp[::-1]
x1 = ''.join(temp)
print (x1)
return str(x)==x1