Skip to content

Instantly share code, notes, and snippets.

@jesuscmadrigal
Created April 11, 2024 23:09
Show Gist options
  • Save jesuscmadrigal/c52e3b4d0cd18543a741220d1d074419 to your computer and use it in GitHub Desktop.
Save jesuscmadrigal/c52e3b4d0cd18543a741220d1d074419 to your computer and use it in GitHub Desktop.
class Solution:
def longestPalindrome(self, s: str) -> str:
result, resultLen = "",0
for i in range(len(s)):
result, resultLen = computePalindrome(i,i, s, result, resultLen)
result, resultLen = computePalindrome(i,i+1, s, result, resultLen)
return result
def computePalindrome(left, right, string, result, resultLen):
while left >= 0 and right < len(string) and string[left] == string[right]:
if (right - left + 1) > resultLen:
result = string[left:right+1]
resultLen = right - left + 1
left -= 1
right += 1
return [result, resultLen]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment