My 1-line python solution

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

  • 1

    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.