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?