Skip to content

#151 - Reverse Words in a String

MediumArray / String
Open on LeetCode

Given an input string s, reverse the order of the words. A word is a maximal sequence of non-space characters. The returned string should have a single space between words and no leading/trailing spaces.

InputOutput
s = "the sky is blue""blue is sky the"
s = " hello world ""world hello"
s = "a good example""example good a"

Released under the MIT License.