网易操作序列的题有java过了的吗
更新:好像是放宽了内存和时间限制,这个代码现在不会超了
完全改写官方解答还是50,内存超限
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] s = new int[n]; for (int i = 0; i < n; i++) { s[i] = in.nextInt(); } if ((n % 2) > 0) { for (int i = n - 1; i >= 0; i -= 2) { System.out.print(s[i] + " "); } for (int i = 1; i <= n - 1; i += 2) { System.out.print(i == n - 2 ? s[i] : s[i] + " "); } } else { for (int i = n - 1; i >= 0; i -= 2) { System.out.print(s[i] + " "); } for (int i = 0; i <= n - 1; i += 2) { System.out.print(i == n - 2 ? s[i] : s[i] + " "); } } } }