My 1-line python solution


  • 1
    H
    class Solution:
        # @param s, a string
        # @return a string
        def reverseWords(self, s):
            return " ".join(s.split()[::-1])

  • 1
    A

    Yes, utilizing the built-in methods of string can reduce the volume of the code heavily.


Log in to reply
 

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