Skip to content

Commit daccb6c

Browse files
committed
Time: 7 ms (81.08%), Space: 19.6 MB (76.76%) - LeetHub
1 parent 16905d3 commit daccb6c

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
class Solution:
22
def isPalindrome(self, s: str) -> bool:
3-
# 1. 문자열 공백 제거 + 문자/숫자가 아닌거 전부 제거
4-
s = "".join(ch for ch in s if ch.isalnum())
3+
# # 리스트 만들고, reverse해서 비교
4+
# convert_s = [ch for ch in s.lower() if ch.isalnum()]
5+
# return convert_s == convert_s[::-1]
56

6-
# 2. 소문자 변환
7-
s = s.lower()
7+
# print(convert_s)
88

9-
# 3. 문자열 뒤집기
10-
reverse_s = s[::-1]
9+
# 투포인터
10+
start, end = 0, len(s)-1
1111

12-
if s == reverse_s:
13-
return True
14-
else:
15-
return False
12+
while start < end:
13+
while start < end and not s[start].isalnum():
14+
start+=1
15+
while start < end and not s[end].isalnum():
16+
end-=1
17+
18+
if s[start].lower() != s[end].lower():
19+
return False
20+
21+
start, end = start+1, end-1
22+
return True

0 commit comments

Comments
 (0)