Advertisement
dbarrera

palindromeSubstring

Feb 3rd, 2022
1,371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. def palindromeSubstring(str):
  2.     maxLongitud = 1
  3.     inicio = 0
  4.     longitud = len(str)
  5.  
  6.     for i in range(longitud):
  7.         for j in range(i, longitud):
  8.             palindrome = True
  9.  
  10.             for k in range(0, ((j - i) // 2) + 1):
  11.                 if(str[i + k] != str[j - k]):
  12.                     palindrome = False
  13.  
  14.             if (palindrome and (j - i + 1) > maxLongitud):
  15.                 inicio = i
  16.                 maxLongitud = j - i + 1
  17.  
  18.     return str[inicio:inicio + maxLongitud]
  19.  
  20. str = 'abracecars'
  21. print(palindromeSubstring(str))
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement