1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
def isPalindromic(s):
ans=''
sLength=len(s)
if sLength%2==0:
if s[:sLength//2] ==s[sLength//2:][::-1] :ans=s
else:
if s[:sLength//2] ==s[sLength//2+1:][::-1] :ans=s
return ans
class Solution:
def firstPalindrome(self, words: List[str]) -> str:
ans=''
for i in words:
if isPalindromic(i)!='' :
ans=isPalindromic(i)
break
return ans
|
cs |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 1464. Maximum Product of Two Elements in an Array (0) | 2022.03.16 |
---|---|
leetcode 125. Valid Palindrome (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 |
leetcode 2089. Find Target Indices After Sorting Array (0) | 2022.03.15 |
댓글