easy +10 pts

Palindromic Number Check

Determine if an integer reads the same forward and backward.

A palindromic number is a number that remains the same when its digits are reversed. For example, 121 is a palindrome, but -121 is not because reversing '-121' gives '121-' which is different. Also, 10 is not a palindrome because reversing '10' gives '01' which equals 1. Write a Python function `is_palindrome_number(n: int) -> bool` that returns `True` if `n` is a palindromic number, and `False` otherwise. The function should handle both positive and negative integers. A negative number is never a palindrome. Numbers ending with zero are not palindromes unless the number is 0 itself. You may solve this by converting the number to a string and comparing it with its reverse, or by any other logic you prefer.

Constraints

Input is an integer within the range -10^9 to 10^9. The function should return a boolean. Time complexity: O(d) where d is the number of digits. Space complexity: O(d) if using string conversion or O(1) with math.

Example

>>> is_palindrome_number(121)
True
>>> is_palindrome_number(-121)
False
>>> is_palindrome_number(10)
False
>>> is_palindrome_number(0)
True
10 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Think about how negative numbers behave.
String reversal can be done with slicing: s[::-1].
Numbers ending with zero are tricky unless the number is 0.
You can also reverse the integer mathematically by popping digits.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.