题解 | 多组_字符串_T组形式
多组_字符串_T组形式
https://www.nowcoder.com/practice/35f6f4e9173943e3b3f462b697fefd8b
import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); StringBuilder output = new StringBuilder(); while (t-- > 0) { int n = Integer.parseInt(br.readLine()); char[] chars = br.readLine().toCharArray(); // 双指针原地交换字符 int left = 0, right = chars.length - 1; while (left < right) { char temp = chars[left]; chars[left++] = chars[right]; chars[right--] = temp; } output.append(new String(chars)).append("\n"); } System.out.print(output); } }