python implementation in 7 lines


  • 0
    X
    class Solution(object):
        def reverseWords(self, s):
            """
            :type s: str
            :rtype: str
            """
            ss = s.split()
            l = len(ss)
            sss = []
            for i in range(l):
                sss.append(ss[l-i-1])
            g = ' '.join(sss)
            return g
    

Log in to reply
 

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