Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Easy solution in Clear category for The Longest Palindromic by Polundra
def longest_palindromic(a):
# your code here
result = a[0]
for i in range(len(a)):
for j in range(i+1, len(a)+1):
if len(a[i:j]) > 1:
if (a[i:j] == a[i:j][::-1]) and (len(a[i:j]) > len(result)):
result = a[i:j]
return result
if __name__ == '__main__':
print("Example:")
print(longest_palindromic('abc'))
# These "asserts" are used for self-checking and not for an auto-testing
assert longest_palindromic('abc') == 'a'
assert longest_palindromic('abacada') == 'aba'
assert longest_palindromic('artrartrt') == 'rtrartr'
assert longest_palindromic('aaaaa') == 'aaaaa'
print("Coding complete? Click 'Check' to earn cool rewards!")
April 25, 2023