TLE for the python solution, why ?


  • 0
    U

    It's timeout for the following python solution, why ?

    def reverseWords(self, s):
        s = s[::-1]
        j = 0
        for i in xrange(len(s)):
            if i == len(s)-1:
                s = s[:j]+s[i:j-1:-1] 
    
            elif s[i] == ' ':
                if j == 0:
                    s = s[:j]+s[i-1::-1] + s[i:]
                else:
                    s = s[:j]+s[i-1:j-1:-1] + s[i:]
                j = i + 1

Log in to reply
 

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