← switch

151. Reverse Words in a String

medium

Two Pointers · String

read the problem on leetcode →

first solved 12 Sept 2026

python
class Solution:
    def reverseWords(self, s: str) -> str:
        slist=s.split()
        return " ".join(slist[::-1])