https://leetcode.com/problems/longest-palindromic-substring
class Solution:
def longestPalindrome(self, s: str) -> str:
def findPalindrome(s: str, left, right) -> str:
while left >= 0 and right < len(s) and s[left] == s[right]:
left -= 1
right += 1
return s[left + 1 : right]
maxLen = 0
maxStr = ""
for i in range(len(s)):
oddPalindrome = findPalindrome(s, i, i)
evenPalindrome = findPalindrome(s, i, i + 1)
if maxLen < len(oddPalindrome):
maxLen = len(oddPalindrome)
maxStr = oddPalindrome
if maxLen < len(evenPalindrome):
maxLen = len(evenPalindrome)
maxStr = evenPalindrome
return maxStr