557. Reverse Words in a String III
Given the string s, it reverses the order of characters in each word in the sentence while preserving spaces and initial word order.
Example 1:
Input: s = "Let's take the LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"
Example 2:
Input: s = "God Ding"
Output: "dog gniD"
Limitations:
1 <= s.length <= 5 * 104
s contains printable ASCII characters.
s contains no leading or trailing spaces.
There is at least one word in s.
All words in s are separated by a single space.
Solution
class Solution {
public:
string reverseWords(string s)
{
int i=0;
for(int j=0; j
Comments
Post a Comment