Skip to content

Commit b8d3fd1

Browse files
authored
Merge pull request neetcode-gh#1744 from AP-Repositories/patch-27
Create 0009-palindrome-number.py
2 parents d0d89f7 + 4da7e93 commit b8d3fd1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

python/0009-palindrome-number.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def isPalindrome(self, x: int) -> bool:
3+
if x < 0: return False
4+
5+
div = 1
6+
while x >= 10 * div:
7+
div *= 10
8+
9+
while x:
10+
right = x % 10
11+
left = x // div
12+
13+
if left != right: return False
14+
15+
x = (x % div) // 10
16+
div = div / 100
17+
return True

0 commit comments

Comments
 (0)