1 line Python


  • 5

    Straightforward one.

    class Solution(object):
        def reverseWords(self, s):
            """
            :type s: str
            :rtype: str
            """
            return " ".join(map(lambda x: x[::-1], s.split()))
    

  • 0
    F

    awesome job!


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

  • 0
    S

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


Log in to reply
 

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