Problem
Given a string s, return its words in reverse order. A word is a run of non-space characters. The input may have leading, trailing, or repeated spaces; the output must have the words separated by a single space with no spaces at the ends.
Example 1
- Input
- s = "the sky is blue"
- Output
- "blue is sky the"
Example 2
- Input
- s = " hello world "
- Output
- "world hello"
Example 3
- Input
- s = "a good example"
- Output
- "example good a"
Try it without split: scan the string with indices.
Constraints
1 <= s.length <= 10^4s contains English letters, digits, and spaces ' '.There is at least one word in s.