Share my 6-lines Python solution


  • 0
    F
    class Solution(object):
        def reverseWords(self, s):
            """
            :type s: str
            :rtype: str
            """
            s=s.strip().split()
            if not s: return ""
            rst=s[0]
            for i in range(1, len(s)):
                rst=(s[i]+" ")+rst
            return rst

Log in to reply
 

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