[LeetCode]#9. Palindrome Number
1 min readSep 2, 2020
Environment: Python 3.7
Key technique: abs
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
Example 1:
Input: 121
Output: true
Analysis:
- If input <0; return False
- If input >0; input switch location such as “123” to "321"
- If input == switched input; return True
Solution:
class Solution:
def isPalindrome(self, x):
if x<0:
return False
s = int(str(abs(x))[::-1])
if(x == s):
return True
Submissions:
Reference:
https://leetcode.com/problems/palindrome-number/discuss/824071/Python-Simplest-using-string