Skip to content

Commit 44f8bd0

Browse files
committed
125. Two pointers. Cleanup
1 parent ef5121b commit 44f8bd0

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
2+
*.iml
23
venv
34
cmake-build-debug

main.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
class Solution:
22
def isPalindrome(self, s: str) -> bool:
33
chars = list(s.lower())
4-
l = len(chars)
4+
chars_count = len(chars)
55

66
p1 = 0
7-
p2 = l - 1
8-
while p1 < l and p2 > 0 and p1 < p2:
9-
n1 = ord(chars[p1])
10-
if (n1 < 97 or n1 > 122) and (n1 < 48 or n1 > 57):
7+
p2 = chars_count - 1
8+
while p1 < chars_count and p2 > 0 and p1 < p2:
9+
s1, s2 = chars[p1], chars[p2]
10+
11+
if not s1.isalnum():
1112
p1 += 1
1213
continue
1314

14-
n2 = ord(chars[p2])
15-
if (n2 < 97 or n2 > 122) and (n2 < 48 or n2 > 57):
15+
if not s2.isalnum():
1616
p2 -= 1
1717
continue
1818

19-
if chars[p1] != chars[p2]:
19+
if s1 != s2:
2020
return False
2121

2222
p1 += 1

0 commit comments

Comments
 (0)