Problem :

https://leetcode.com/problems/valid-palindrome/description/


My Solution :

class Solution:
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
i = 0
j = len(s)-1
while i < j:
while i < j and not s[i].isalnum():
i += 1
while i < j and not s[j].isalnum():
j -= 1
if s[i].lower() != s[j].lower():
return False
i += 1
j -= 1
return True


Comment :

Python str class는 isalnum, isalpha, isdigit, islower, isupper 등의 편리한 method를 가지고 있다.