找出数组中出现次数超过数组长度一半的数字
import java.util.*;public class haha{public static void main(String[] args) {Scanner sc=new Scanner(System.in);int n=sc.nextInt();int a[]=new int[n];int coun...
·
import java.util.*;
public class haha{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[]=new int[n];
int count=0;
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
Arrays.sort(a);
for(int i=0;i<n;i++){
if(a[i]==a[a.length/2]){
count++;
}
}
if(count>a.length/2){
System.out.println(a[a.length/2]);
}else{
System.out.println(0);
}
}
}
昇腾计算产业是基于昇腾系列(HUAWEI Ascend)处理器和基础软件构建的全栈 AI计算基础设施、行业应用及服务,https://devpress.csdn.net/organization/setting/general/146749包括昇腾系列处理器、系列硬件、CANN、AI计算框架、应用使能、开发工具链、管理运维工具、行业应用及服务等全产业链
更多推荐

所有评论(0)