Leetcode Problem 151. Reverse Words in a String

151. Reverse Words in a String

Leetcode Solutions

Approach: Built-in Split + Reverse

  1. Use the split function to divide the input string s into a list of words, splitting by spaces.
  2. Reverse the list of words.
  3. Use the join function to concatenate the reversed list of words into a single string, with each word separated by a single space.
UML Thumbnail

Approach: Reverse the Whole String and Then Reverse Each Word

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...