Python One Liner


  • 0
    W

    It's absolutely hideous

    class Solution(object):
        def reverseWords(self, s):
            """
            :type s: str
            :rtype: str
            """
            return "".join([(" " + x) for x in s.split(" ") if x != ""][::-1])[1::]
    

  • 0
    W

    More Pythonic: return ' '.join(reversed(s.strip().split()))


Log in to reply
 

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