File tree Expand file tree Collapse file tree 1 file changed +6
-13
lines changed Expand file tree Collapse file tree 1 file changed +6
-13
lines changed Original file line number Diff line number Diff line change 1
1
"""
2
- Title: 215. Valid Palindrome
3
- Link: https://leetcode.com/problems/valid-palindrome/
4
-
5
- Summary:
6
- - Palindrome이라면 True, 아니라면 False를 반환하는 문제.
7
- - Palindrome이란, 앞으로 읽어도 뒤에서부터 읽어도 동일한 단어를 뜻함.
8
- - 추가 조건: 대소문자를 구분하지 않으며, 알파벳과 숫자 이외의 문자는 제거해야 함.
9
- - e.g. racecar
10
-
11
2
Conditions:
12
- - 입력 문자열이 Palindrome인 경우: `True` 반환
13
- - Palindrome이 아닌 경우: `False` 반환
3
+ - 1 <= s.length <= 2 * 10^5
4
+ - s consists only of printable ASCII characters.
14
5
15
6
Time Complexity:
16
- - O(n)
7
+ - O(n)
17
8
Space Complexity:
18
- - O(n)
9
+ - O(n)
19
10
"""
11
+ # Solution 1
20
12
class Solution :
21
13
def isPalindrome (self , s : str ) -> bool :
22
14
s = re .sub (r'[^a-zA-z0-9]' , '' , s ).lower ()
23
15
if s == s [::- 1 ]:
24
16
return True
25
17
return False
26
18
19
+ # Solution 2
You can’t perform that action at this time.
0 commit comments