dsa · easy
Reverse Words in a String III
Reverse the characters of each word in s. A word is a contiguous run of non-space characters. Spaces stay where they are (including when several spaces sit together); only the letters inside each word flip.
Example
s = "Fox in socks".
Three words: "Fox" → "xoF", "in" → "ni", "socks" → "skcos". Join them with the original single spaces → "xoF ni skcos".
s = "ab" is one word, so the whole string reverses → "ba".
s = "a" is already a one-letter word → "a".
## Arguments - s — string of words separated by spaces
Constraints
1 <= s.length <= 5*10^4 s consists of printable ASCII Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: "Fox in socks" Expected: xoF ni skcos
Example 2
Input: "ab" Expected: ba
Example 3
Input: "a" Expected: a