时间复杂度是n方,外循环遍历数组,内循环统计数目
奉上java满分代码
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int n = Integer.parseInt(scanner.nextLine());
String[] line = scanner.nextLine().split(" ");
int[] numbers = new int[n];
for(int i = 0; i < n; i++){
numbers[i] = Integer.parseInt(line[i]);
}
scanner.close();
int number = -1;
for(int numI : numbers){
int bigger = 0;
int smaller = 0;
for(int numJ : numbers){
if(numI > numJ)
bigger++;
if(numI < numJ)
smaller++;
}
if(smaller == bigger){
number = numI;
break;
}
}
System.out.println(number);
}
}