본문 바로가기
python-algorithm

leetcode 125. Valid Palindrome

by 무적김두칠 2022. 3. 15.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
def isPalindromic(s):
    ans=False
    convertedS=''
    for i in s:
        i=i.lower()
        #i=i.replace(" ",'')
        if i.isalnum(): convertedS+=i
    sLength=len(convertedS)
    if sLength%2==0:
        if convertedS[:sLength//2==convertedS[sLength//2:][::-1] :ans=True
    else:
        if convertedS[:sLength//2==convertedS[sLength//2+1:][::-1] :ans=True
    return ans
class Solution:
    def isPalindrome(self, s: str-> bool:
        return isPalindromic(s)
cs
반응형

댓글