The fifth question of Python:leetcode is the enumeration method of, Longest Palindromic Substring, center.

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.

Mar.05,2021

cannot be deleted. Because when it conforms to the situation, x will increase itself.


if you delete x + = 1 , x will never change, and the condition of while may never be satisfied, so it will loop infinitely, so it will time out

.
  • Leetcode longest common prefix, code running problem

    there is a problem with the longest common prefix on leetcode. I want to solve it in a different way, but what I typed is: fl fl flo Why does print have three results? class Solution: def inter_prefix(self,strs=list,minPrefix=str): if minPref...

    Mar.12,2021
  • Algorithm: similar to N SUM problem solving

    topic description similar to the problem of N SUM, the idea comes from a small task encountered in the work, abstracted out: has m items, and gives the unit price of each item, P1 br P2, P3 br. Now there are n orders, and the total amount of each ord...

    Mar.28,2022
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b31229-2bd7a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b31229-2bd7a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?