Skip to content

Commit 5b93269

Browse files
committed
solved with 2 pointers
1 parent 488270e commit 5b93269

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

leetcode.com/palindrome-number.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212

1313
class Solution:
1414
def isPalindrome(self, x: int) -> bool:
15-
return True if str(x)[::-1] == str(x) else False
15+
x = str(x)
16+
l, r = 0, len(x) - 1
17+
while l < r:
18+
if x[l] != x[r]:
19+
return False
20+
l += 1
21+
r -= 1
22+
return True
23+
# return True if str(x)[::-1] == str(x) else False
1624

1725

1826
x = 121

0 commit comments

Comments
 (0)