private static double testHeap(Integer[] testData,boolean isHeapify) {
Long startime=System.nanoTime();
MaxHeap maxHeap;
if(isHeapify) {
maxHeap=new MaxHeap<>(testData);
}else {
maxHeap=new MaxHeap<>();
for(int num:testData) {
maxHeap.add(num);
}
}
int[] arr = new int[testData.length];
for (int i = 0; i < testData.length; i++) {
arr[i] = maxHeap.extractMax();
}
for (int i = 1; i < testData.length; i++) {
if (arr[i - 1] < arr[i]) {
throw new IllegalArgumentException(“Error”);
}
}
System.out.println(“true”);
Long endtime=System.nanoTime();
return (endtime-startime)/1000000000;
}
老师,这串代码放到LeetCode上会报错,说是因为静态方法中不可以声明非静态对象,但是在eclipse中却可以