-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpalindrome-number.py
More file actions
40 lines (31 loc) · 1.25 KB
/
palindrome-number.py
File metadata and controls
40 lines (31 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# https://leetcode.com/problems/palindrome-number/
# Determine whether an integer is a palindrome. Do this without extra space.
#
# click to show spoilers.
#
# Some hints:
# Could negative integers be palindromes? (ie, -1)
#
# If you are thinking of converting the integer to string, note the restriction of using extra space.
#
# You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case?
#
# There is a more generic way of solving this problem.
#
# Subscribe to see which companies asked this question
import unittest
class Solution:
# @return a boolean
def isPalindrome(self, x):
return str(x) == str(x)[::-1]
class TestIsPalindrome(unittest.TestCase):
my_solution = Solution()
def test_default_pass(self):
self.assertTrue(self.my_solution.isPalindrome(121))
def test_not_a_palindrome(self):
self.assertFalse(self.my_solution.isPalindrome(123143))
def test_for_zero(self):
self.assertTrue(self.my_solution.isPalindrome(0))
if __name__ == "__main__":
unittest.main()
# Just realized , I converted the integer to a string , so - I suppose this is not a valid solution in that case