Skip to content

Instantly share code, notes, and snippets.

@ceth-x86
Created January 7, 2021 06:15
Show Gist options
  • Save ceth-x86/c08b862f24839c68073e53bc2571daf0 to your computer and use it in GitHub Desktop.
Save ceth-x86/c08b862f24839c68073e53bc2571daf0 to your computer and use it in GitHub Desktop.
class Solution:
def longestPalindrome(self, s: str) -> str:
res = ""
for i in range(len(s)):
res = max(self.helper(s, i, i), self.helper(s, i, i+1), res, key=len)
return res
def helper(self, s, l, r):
while 0 <= l and r < len(s) and s[l] == s [r]:
l -= 1; r += 1
return s[l+1:r]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment