2 ms·
I didn't want to post code, but I guess it's the only way I can see to settle the debate. This should be manifestly linear. def check(s): is_palind
by im3w1l 6y ago
I didn't want to post code, but I guess it's the only way I can see to settle the debate. This should be manifestly linear.
def check(s):
is_palindrome = lambda s: s == s[::-1]
if is_palindrome(s):
return True
d = [a==b for a, b in zip(s, s[::-1])].index(False)
return is_palindrome(s[d+1:len(s)-d]) or is_palindrome(s[d:-d-1])
edit: It must be len(s)-d rather than -d, to handle d=0.