| 20 | |
| 21 | |
| 22 | class Solution: |
| 23 | def longestPalindrome(self, s: str) -> str: |
| 24 | longest = "" |
| 25 | size = len(s) |
| 26 | for i in range(size): |
| 27 | #Odd Palindrome |
| 28 | left,right = i,i |
| 29 | ls = "" |
| 30 | while 0<=left<size and 0<=right<size and s[left]==s[right]: |
| 31 | if left==right: |
| 32 | ls = s[left] |
| 33 | else: |
| 34 | ls = s[left] + ls + s[right] |
| 35 | left-=1 |
| 36 | right+=1 |
| 37 | #Even Palindrome |
| 38 | left,right = i,i+1 |
| 39 | rs = "" |
| 40 | while 0<=left<size and 0<=right<size and s[left]==s[right]: |
| 41 | rs = s[left] + rs + s[right] |
| 42 | left-=1 |
| 43 | right+=1 |
| 44 | temp = ls if len(ls)>len(rs) else rs |
| 45 | longest = temp if len(temp)>len(longest) else longest |
| 46 | return longest |
nothing calls this directly
no outgoing calls
no test coverage detected