Skip to content

Commit b25f6bd

Browse files
committed
problem solution & test 0009
1 parent c75c32a commit b25f6bd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def isPalindrome(self, x: int) -> bool:
3+
if x < 0 or (x % 10 == 0 and x != 0):
4+
return False
5+
reversed_half = 0
6+
while x > reversed_half:
7+
reversed_half = reversed_half * 10 + (x % 10)
8+
x //= 10
9+
return x == reversed_half or x == reversed_half // 10
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from solutions.palindrome_number_0009 import Solution
2+
3+
def test_is_palindrome():
4+
sol = Solution()
5+
assert sol.isPalindrome(121) == True
6+
assert sol.isPalindrome(-121) == False
7+
assert sol.isPalindrome(10) == False
8+
assert sol.isPalindrome(0) == True
9+
assert sol.isPalindrome(1221) == True
10+
assert sol.isPalindrome(12321) == True
11+
assert sol.isPalindrome(123) == False

0 commit comments

Comments
 (0)