File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change 11def is_palindrome (number : int ) -> bool :
22 """
3- Determines if an integer is a palindrome without string conversion.
3+ Determines if an integer is a palindrome without using string conversion.
44
55 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.
6+ 1. Negative numbers are not palindromes.
7+ 2. Numbers ending in 0 (except 0 itself) are not palindromes.
8+ 3. Reverse half of the number and compare.
9+
10+ Examples:
11+ >>> is_palindrome(121)
12+ True
13+ >>> is_palindrome(12321)
14+ True
15+ >>> is_palindrome(10)
16+ False
17+ >>> is_palindrome(-121)
18+ False
19+ >>> is_palindrome(0)
20+ True
921 """
1022 if number < 0 or (number % 10 == 0 and number != 0 ):
1123 return False
You can’t perform that action at this time.
0 commit comments