1 Line Python, with list comprehension

  • 0

    Straight forward 1-line python solution. Splits the user's input by space, uses list comprehension to reverse each resulting word, then joins the reversed words by a space.

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

Log in to reply

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