python-algorithm
leetcode 2108. Find First Palindromic String in the Array
무적김두칠
2022. 3. 15. 16:25
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 |
반응형