题目描述
Given a string str consisting of multiple words, reverse alternate words in str.
Example 1:
Input:
str = geeks for geeks
Output: geeks rof geeks
Explanation: First and thrid word are as it is.
Second word is reversed.
Example 2:
Input:
str = hello there peter pan
Output: hello ereht peter nap
Explanation: second and fourth words are reversed.
Your Task:
You dont need to read input or print anything. Complete the function reverseAlternate() which takes string str as input parameter and returns the resultant string.
Expected Time Complexity: O(N) where N is the length of str.
Expected Auxiliary Space: O(N)
Constraints:
1<= str.length() <= 10^{4}
输入格式
见题面
输出格式
见题面
样例输入
str = geeks for geeks
样例输出
geeks rof geeks