186. Reverse Words in a String II

Given a character array s (a string represented as an array of characters), reverse the order of words in-place. A word is defined as a maximal sequence of characters without spaces. There are no leading or trailing spaces, and exactly one space separates words.

The intended solution reverses the whole array and then reverses each word, which uses O(1) extra space. The platform returns the resulting character array.

Examples
Input: ["a"]
Output: ["a"]
Hints
Related Problems

186. Reverse Words in a String II

Given a character array `s` (a string represented as an array of characters), reverse the order of words in-place. A word is defined as a maximal sequence of characters without spaces. There are no leading or trailing spaces, and exactly one space separates words.