Description
Given a character array s representing a sentence, reverse the order of words in-place. Words are separated by single spaces.
Examples
Input:
s = ["t","h","e"," ","s","k","y"," ","i","s"," ","b","l","u","e"]Output:
["b","l","u","e"," ","i","s"," ","s","k","y"," ","t","h","e"]Explanation:
Reverse words.
Input:
hello worldOutput:
world helloExplanation:
With only two words, reversing their order: 'hello world' becomes 'world hello'.
Input:
aOutput:
aExplanation:
Single character with no spaces remains unchanged since there's only one word to reverse.
Constraints
- •
1 ≤ s.length ≤ 10⁵