AcWing 816. 数组翻转(java,双指针)
原题链接
简单
作者:
sophon666
,
2025-03-13 21:18:30
·天津
,
所有人可见
,
阅读 1
import java.util.Scanner;
public class Main {
private static void reverse(int a[], int size) {
for (int i = 0, j = size - 1; i < j; i++, j--) { //双指针
int t = a[i];
a[i] = a[j];
a[j] = t;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), size = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
reverse(a, size);
for (int i = 0; i < n; i++) {
System.out.printf("%d ",a[i]);
}
}
}