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 0e36cfa commit c7827a6Copy full SHA for c7827a6
palindrome_number/solution.py
@@ -0,0 +1,27 @@
1
+class Solution:
2
+ # @return a boolean
3
+ def isPalindrome(self, x):
4
+ if x < 0:
5
+ return False
6
+ num_digit = 0
7
+ y = x
8
+ while y != 0:
9
+ y /= 10
10
+ num_digit += 1
11
+ if num_digit <= 1:
12
+ return True
13
+ # Reverse the right half
14
+ i = 0
15
+ t = 0
16
+ while i < num_digit / 2:
17
+ t = t * 10 + x % 10
18
+ x /= 10
19
+ i += 1
20
+ # Remove the middle digit if num_digit is odd
21
+ if num_digit % 2 == 1:
22
23
+ # Compare t and x
24
+ if t == x:
25
26
+ else:
27
0 commit comments