Reverse Words in a String III
Easy · two pointers
You are given a sentence s: words made of letters and digits, separated by single spaces. There is no space at the start or at the end, and never two spaces in a row.
Return the sentence with the letters of every word reversed. The words stay in their original positions, and the spaces stay where they are.
Examples
Example 1
Input: s = "tea and biscuits"
Output: "aet dna stiucsib"
Each word is reversed on its own: tea becomes aet, and becomes dna, biscuits becomes stiucsib.
Example 2
Input: s = "Ab1 Cd2"
Output: "1bA 2dC"
Capital letters and digits move with the rest of the word. Nothing is changed except the order of the characters inside each word.
Example 3
Input: s = "level"
Output: "level"
A single word that reads the same both ways is unchanged.
Constraints
- 1 <= len(s) <= 10^4
- s contains only English letters, digits and the space character.
- s has no leading or trailing space and no two consecutive spaces.