Why my solution is wrong?


  • -1
    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 ' ' in s and s != ' ':
                s.reverse()
                index = 0
                for i in range(len(s)):
                    if s[i] == ' ':
                        s[index: i] = s[i-1:index-1:-1]
                        index = i + 1
                s[index:] = s[:index-1:-1]
    

Log in to reply
 

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