Why my python error is " Time Limit Exceeded"?

  • 0
    class Solution(object):
        def reverseString(self, s):
            :type s: str
            :rtype: str
            ans = ""
            for i in range(len(s)-1,-1,-1):
                ans = ans + s[i]
            return ans

    the error is "Time Limit Exceeded", and it happened at the last test case.
    The last test case is a very very long string, which has many lines.
    How could python deal with a string with many lines?
    And why my code has problem? Is its time complexity too high?

Log in to reply

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