Skip to content

Commit 19f404d

Browse files
committed
Palindrome Integer
1 parent fda4591 commit 19f404d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)