Reverse Words in a String III Java Solution - The Coding Shala
Home >> Interview Questions >> Reverse Words in a String 3
Reverse Words in a String III
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
Input: "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"
Note: In the string, each word is separated by a single space and there will not be any extra space in the string.
Reverse Words in a String III Java Solution
Using StringBuilder and reverse we can do it.
We can convert String into a char array and then reverse the char till space.
Other Posts You May Like