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 |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 1704. Determine if String Halves Are Alike (0) | 2022.03.16 |
---|---|
leetcode 1464. Maximum Product of Two Elements in an Array (0) | 2022.03.16 |
leetcode 2108. Find First Palindromic String in the Array (0) | 2022.03.15 |
leetcode 2176. Count Equal and Divisible Pairs in an Array (0) | 2022.03.15 |
leetcode 1844. Replace All Digits with Characters (0) | 2022.03.15 |
댓글