Skip to content

Commit 6b82dfc

Browse files
committed
leetcode.com 125. Valid Palindrome
문제 링크: https://leetcode.com/problems/valid-palindrome
1 parent d8891ef commit 6b82dfc

File tree

1 file changed

+24
-0
lines changed
  • leetcode.com 125. Valid Palindrome v2

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution:
2+
def isPalindrome(self, s: str) -> bool:
3+
dt = ''
4+
5+
for c in s:
6+
if c.isalnum():
7+
dt += c.lower()
8+
9+
return self.is_palindrome(dt)
10+
11+
def is_palindrome(self, dt):
12+
if dt == '':
13+
return True
14+
15+
idx_left, idx_right = 0, len(dt) - 1
16+
17+
while idx_left <= idx_right:
18+
if dt[idx_left] != dt[idx_right]:
19+
return False
20+
21+
idx_left += 1
22+
idx_right -= 1
23+
24+
return True

0 commit comments

Comments
 (0)