大佬帮我看看猿辅导笔试第一题为什么通不过
自己本地IDE能过 为什么提交就是0呢,感谢大佬
import java.util.ArrayList;
import java.util.Scanner;
class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int n = sc.nextInt();
int[] nodenum = new int[n];
for (int i = 0; i < n; i++) {
nodenum[i] = sc.nextInt();
}
ArrayList<Integer> ans = help(nodenum);
System.out.println(ans);
}
}
public static ArrayList<Integer> help(int[] arr) {
ArrayList<Integer> list=new ArrayList<>();
int i=0;
int index=(int) (Math.pow(2, i)-1);
int nextIndex=(int) (Math.pow(2, i+1)-1);
while(nextIndex<arr.length) {
list.add(arr[index]);
i++;
index=(int) (Math.pow(2, i)-1);
nextIndex=(int) (Math.pow(2, i+1)-1);
}
for(int j=index;j<arr.length;j++) {
list.add(arr[j]);
}
index=index-1;
while(index>0) {
list.add(arr[index]);
i--;
index=(int) (Math.pow(2, i)-1)-1;
}
return list;
}
}
#猿辅导##笔试题型#
