Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Integer Palindrome by colinmcnicholl
from collections import deque
def int_palindrome(number: int) -> bool:
'''Input: Integer
Output: Boolean True if the input number is a palindrome,
False otherwise.
'''
stack = []
queue = deque()
quotient = 'inf'
while quotient != 0:
quotient, remainder = divmod(number, 10)
stack.append(remainder)
number = quotient
stack_copy = stack.copy()
while (len(stack) > 0):
queue.append(stack.pop())
for val in stack_copy:
if val != queue.popleft():
return False
return True
print("Example:")
print(int_palindrome(151))
assert int_palindrome(151) == True
assert int_palindrome(212) == True
assert int_palindrome(321) == False
print("The mission is done! Click 'Check Solution' to earn rewards!")
Sept. 6, 2022
Comments: