1. What I learned
reversing a string
To reverse a string, write as follows.
str_sam = 'hello'
print(str_sam[::-1])
#It will print 'olleh'
2. How I sloved
I had to check if the number was symmetrical. If the number was negative, it could not be symmetrical. So if the number was zero or positive, then the number was compared to the upside-down number to confirm that it was symmetrical.
3. Code
class Solution:
def isPalindrome(self, x: int) -> bool:
if x>=0 and str(x)==str(x)[::-1]:
return True
return False
4. Result
Runtime : 48 ms(94.78%), Memory usage : 14.2 MB(100.00%)
(Runtime can be different by a system even if it is a same code.)