Why time limit is exceeded?

  • 0

    I tried the following code on my IDE and it takes 0.03 seconds to calculate the output. I have no idea about why TLE on leetcode. Does any have any ideas for this? Thank you!

    class Solution(object):
        def validPalindrome(self, s):
            :type s: str
            :rtype: bool
            while len(s) > 1:
                if s[0] != s[-1]:
                    return s[1:] == s[:0:-1] or s[:-1] == s[-2::-1]
                    s = s[1:-1]
            return True

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.