You are viewing a single comment's thread. Return to all comments →
the solution is: def ispalindromes(s): return s==s[::-1]
def palindromeIndex(s): n=len(s) if ispalindromes(s): return -1
for i in range(n//2): if s[i]!=s[n-i-1]: if ispalindromes(s[:1]+s[i+1:]): return i else: return n-i-1 return -1
Seems like cookies are disabled on this browser, please enable them to open this website
Palindrome Index
You are viewing a single comment's thread. Return to all comments →
the solution is: def ispalindromes(s): return s==s[::-1]
def palindromeIndex(s): n=len(s) if ispalindromes(s): return -1