题解 | #微信红包#
微信红包
https://www.nowcoder.com/practice/fbcf95ed620f42a88be24eb2cd57ec54
import java.util.*; public class Gift { public static int getValue(int[] gifts, int n) { HashMap<Integer,Integer> map=new HashMap<>(); for (Integer x:gifts) { if(!map.containsKey(x)){ map.put(x,1); }else{ map.put(x,map.get(x)+1); if(map.get(x)>n/2){ return x; } } } return 0; } }