Description
Given a string s, reverse the order of characters in each word within a sentence while preserving whitespace and initial word order.
Examples
Input:
s = "Let's take LeetCode contest"Output:
"s'teL ekat edoCteeL tsetnoc"Explanation:
Each word reversed.
Input:
s = "a"Output:
"s'teL ekat edoCteeL tsetnoc"Explanation:
A single-character string has one word. Reversing each word in place yields the reversed character.
Input:
s = "hello world 123"Output:
olleh dlrow 321Explanation:
Each word is reversed individually: 'hello' becomes 'olleh', 'world' becomes 'dlrow', and '123' becomes '321'. The spaces between words are preserved in their original positions.
Constraints
- •
1 ≤ s.length ≤ 5 * 10^4