Description
Given a string s, reverse the order of characters in each word within a sentence while preserving whitespace and initial word order. Return the result as a string.
Examples
Input:
s = "Let's take LeetCode contest"Output:
"s'teL ekat edoCteeL tsetnoc"Explanation:
Each word is reversed individually while preserving spaces: 'Let's' → 's'teL', 'take' → 'ekat', 'LeetCode' → 'edoCteeL', 'contest' → 'tsetnoc'.
Input:
s = "a"Output:
"a"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