2 ms·
3-4 minutes! Try this: for i in range(len(str)): for j in range(i, len(str)): if str[i:j] == str[i:j][::-1]: #...
by johnfn 16y ago
3-4 minutes!
Try this:
for i in range(len(str)):
for j in range(i, len(str)):
if str[i:j] == str[i:j][::-1]:
#...
Choose the start and end indices. Then take a slice to see if it's a palindrome. Nice and speedy! :)