第一题AC,评论有字数限制,我分两条发 import java.util.ArrayList; import java.util.Scanner; public class YuanFuDao01 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); if (N <= 0) { return; } int []arr = new int[N]; for (int i = 0; i < N; i++) { arr[i] = scanner.nextInt(); } int index = 0; ArrayList<Integer> arrayList = new ArrayList<>(); arrayList.add(arr[index]); while (index*2+1 <= N-1) { index = index*2+1; arrayList.add(arr[index]); } int temp = index-1; while (index < N-1) { index++; arrayList.add(arr[index]); }
点赞 评论
牛客网
牛客企业服务