Accepted Python Solution

  • 1
    class Solution:
        # @param s, a string
        # @return a string
        def reverseWords(self, s):        
            a = s.strip().split(" ")    
            b = []
            for i in a:
                if i != "":
            return ' '.join(b)

  • 1

    You actually don't have to strip the string if you're checking empty space anyways.

Log in to reply

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