Skip to content

Commit d9464aa

Browse files
committed
leetcode - 125
1 parent 2a64e32 commit d9464aa

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

python/string/leetcode_125.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# LeetCode
2+
# 125. Valid Palindrome
3+
# https://leetcode.com/problems/valid-palindrome/
4+
5+
class Solution:
6+
def isPalindrome(self, s: str) -> bool:
7+
8+
# 나라면 대문자를 모두 소문자로 바꾼 다음에, 문자가 아닌 것들을 전부 제거할 것 같습니다.
9+
# 1. 문자만 놔둠
10+
# 2. 소문자로 다 바꿈
11+
# 3. 뒤집었을 때 같은지 확인
12+
13+
temp = ""
14+
# 알파벳이라면
15+
16+
for i in s:
17+
if i.isalnum():
18+
temp += i.lower()
19+
20+
if temp == temp[::-1]:
21+
return True
22+
else:
23+
return False

0 commit comments

Comments
 (0)