Reverse Words in a String

Problem Id: 151 Difficulty: Medium


Intuition

Solution


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