We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b1779c5 commit 12bcdb8Copy full SHA for 12bcdb8
1 file changed
maths/palindrome_number.py
@@ -1,11 +1,23 @@
1
def is_palindrome(number: int) -> bool:
2
"""
3
- Determines if an integer is a palindrome without string conversion.
+ Determines if an integer is a palindrome without using string conversion.
4
5
Logic:
6
- 1. Filter out negative numbers and multiples of 10.
7
- 2. Reverse the second half of the number.
8
- 3. Compare the two halves.
+ 1. Negative numbers are not palindromes.
+ 2. Numbers ending in 0 (except 0 itself) are not palindromes.
+ 3. Reverse half of the number and compare.
9
+
10
+ Examples:
11
+ >>> is_palindrome(121)
12
+ True
13
+ >>> is_palindrome(12321)
14
15
+ >>> is_palindrome(10)
16
+ False
17
+ >>> is_palindrome(-121)
18
19
+ >>> is_palindrome(0)
20
21
22
if number < 0 or (number % 10 == 0 and number != 0):
23
return False
0 commit comments