1. Doing exercises on leetcode, the fifth question, using the central enumeration method.
2. Refer to this blog post: https://blog.csdn.net/asd1369.
3. The second method used, other code can understand, I directly posted the question code:
x= 0
if (i + 1) < l:
while (i - x) >= 0 and (i + 1 + x) < l:
if s[i + 1 + x] == s[i - x]:
x += 1
else:
break
4. I thought it was unnecessary to do the"+","- "operation on x, so I deleted it (it was deleted in the while and if statements).
5. After deletion, the code that could have passed has timed out.
6. I hope someone can tell me why this happened.