Skip to content

Commit f295e2f

Browse files
committed
Valid palindrome solutiuon
1 parent 637ca7d commit f295e2f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

valid-palindrome/ohkingtaek.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, s: str) -> bool:
3+
"""
4+
- 시간복잡도: O(n)
5+
- 공간복잡도: O(n)
6+
1. 문자열을 소문자로 변환하고, 알파벳과 숫자만 남기기
7+
2. 남은 문자열을 절반으로 나누고, 앞과 뒤를 비교하여 회문인지 확인
8+
3. 회문이면 True, 아니면 False 반환
9+
"""
10+
a = ""
11+
for i in s.lower():
12+
if i.isalnum():
13+
a += i
14+
for i, j in zip(a[:len(a) // 2], a[len(a):(len(a) // 2 - 1):-1]):
15+
if i != j:
16+
return False
17+
return True

0 commit comments

Comments
 (0)