Created
January 7, 2021 06:15
-
-
Save ceth-x86/c08b862f24839c68073e53bc2571daf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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