import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param numbers int整型一维数组 * @return int整型 */ public int MoreThanHalfNum_Solution (int[] numbers) { Scanner scanner = new Scanner(System.in); HashMap<Integer,Integer> map = new HashMap<>(); int len = numbers.length; for(int x : numbers) { map.put(x,map.getOrDefault(x,0)+1); } int max = 0; for(int x : numbers) { if(map.get(x) > len/2) { max = x; } } return max; } }