Description
Given a string s, reverse the order of characters in each word within a sentence while preserving whitespace and initial word order. A word is defined as a sequence of non-space characters.
Examples
Input:
s = "Let's take LeetCode contest"Output:
"s'teL ekat edoCteeL tsetnoc"Explanation:
Each word reversed.
Input:
s = "Hello World"Output:
"olleH dlroW"Explanation:
Each word is reversed individually: 'Hello' becomes 'olleH' and 'World' becomes 'dlroW', while the space between them is preserved.
Input:
s = "a"Output:
"a"Explanation:
Single character strings remain unchanged when reversed, demonstrating the edge case of minimal input length.
Constraints
- •
1 ≤ s.length ≤ 5 × 10⁴