File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments