52ms python solution


  • 0
    Y
    class Solution:
        # @param s, a list of 1 length strings, e.g., s = ['h','e','l','l','o']
        # @return nothing
        def reverseWords(self, s):
            if not s:
                return 
            s.reverse()
            i=0
            while i<len(s):
                try:
                    j=s.index(' ',i)
                    s[i:j]=s[i:j][::-1]
                    i=j+1
                except Exception:
                    s[i:]=s[i:][::-1]
                    return

Log in to reply
 

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