P19894 [GeeksforGeeks] Special array reversal2328
普及-
题目描述

Given a string S, containing special characters and all the alphabets, reverse the string without
affecting the positions of the special characters.
Example 1:
Input: S = "A&B"
Output: "B&A"
Explanation: As we ignore '&' and
then reverse, so answer is "B&A".
Example 2:
Input: S = "A&x#
Output: "x&A#"
Explanation: we swap only A and x.
Your Task:
You don't need to read input or print anything. Your task is to complete the function reverse() which takes the string as inputs and returns required reverse string.
Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(|S|)
Constraints:
1 ≤ |S| ≤ 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
S = "A&B"
样例输出
"B&A"