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 fda4591 commit 19f404dCopy full SHA for 19f404d
Python/Interviewbit/Math/palindrome-integer.py
@@ -0,0 +1,27 @@
1
+"""
2
+Problem Link: https://www.interviewbit.com/problems/palindrome-integer/
3
+
4
+Determine whether an integer is a palindrome. Do this without extra space.
5
+A palindrome integer is an integer x for which reverse(x) = x where reverse(x) is x with
6
+its digit reversed.
7
8
+Negative numbers are not palindromic.
9
10
+Example :
11
+Input : 12121
12
+Output : True
13
14
+Input : 123
15
+Output : False
16
17
+class Solution:
18
+ # @param A : integer
19
+ # @return an integer
20
+ def isPalindrome(self, x):
21
+ if x < 0 or (x % 10 == 0 and x != 0):
22
+ return 0
23
+ rev = 0
24
+ while x > rev:
25
+ rev = (rev*10) + (x%10)
26
+ x //= 10
27
+ return int(rev == x or rev//10 == x)
0 commit comments