Accepted Python Solution


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

  • 1
    J

    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.