80. Reverse Words in a String

Reverse the order of words in the string. Extra spaces should be removed.
Example 1
Input: s = " hello world "
Output: "world hello"
Explanation: Leading, trailing, and extra spaces between words are normalized.
Example 2
Input: s = "the sky is blue"
Output: "blue is sky the"
Explanation: Words are swapped and extra spaces are removed.
mediumstrings
JavaScript
Loading...
Line 1, Char 1