Skip to content

Instantly share code, notes, and snippets.

@dongr0510
Created September 12, 2020 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dongr0510/8b2d3255479c4de4120f6547bc6aa0f6 to your computer and use it in GitHub Desktop.
Save dongr0510/8b2d3255479c4de4120f6547bc6aa0f6 to your computer and use it in GitHub Desktop.
def longestPalindrome(s):
return find_LPS_recursive(st, 0, len(st)-1)
def find_LPS_recursive(s, s_Index, e_Index):
if s_Index > e_Index:
return 0
if s_Index = endIndex:
return 1
if s[s_Index] == s[e_Index]:
return 2 + find_LPS_recursive(s, s_Index+1, e_Index-1)
c1 = find_LPS_recursive(st, s_Index+1, e_Index)
c2 = find_LPS_recursive(st, s_Index, e_Index-1)
return max(c1, c2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment