Skip to content
LC-0151 Medium LeetCode

151. Reverse Words in a String

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 51% Topics: Two Pointers, String
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(n)

class Solution(object):
    # @param s, a string
    # @return a string
    def reverseWords(self, s):
        return ' '.join(reversed(s.split()))

Solution from kamyu104/LeetCode-Solutions · MIT