this entry collects the solution files i have for palindrome number. i may expand it with a fuller write-up later, but the implementation files are already here.
available solution files
- Python
palindrome-number/solution.py
notes and solution files for palindrome number.
this entry collects the solution files i have for palindrome number. i may expand it with a fuller write-up later, but the implementation files are already here.
palindrome-number/solution.pyclass Solution(object):
def isPalindrome(self, x):
if x < class="syntax-number">0:
return False
original = x
reversed_number = class="syntax-number">0
while x > class="syntax-number">0:
last_digit = x % class="syntax-number">10
reversed_number = reversed_number * class="syntax-number">10 + last_digit
x = x class=class="syntax-string">"syntax-comment">// class="syntax-number">10
return original == reversed_number
solution = Solution()
print(solution.isPalindrome(class="syntax-number">121))
print(solution.isPalindrome(-class="syntax-number">121))
print(solution.isPalindrome(class="syntax-number">10))