/** * 返回数组中的最大元素个数 * 约束: * 数组大小 1<=size<=10to5 * 数组元素大小 1<=arrList[i]<=10to7 * @param candles * @return */ public static int birthdayCakeCandles(List<Integer> candles){ if (candles==null){ return 0; } if(candles.isEmpty()){ return 0; } int val=1; for (int i = 0; i < 5; i++) { val*=10; } if (candles.size()<1 || candles.size()>val){ return 0; } int val1=1; for (int i = 0; i < 7; i++) { val1*=10; } for (int i = 0; i < candles.size(); i++) { Integer i1 = candles.get(i); if (i1<1 || i1 >val1) { return 0; } } Collections.sort(candles, new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { if (o1>o2){ return 1; }else if(o1<o2){ return -1; }else { return 0; } } }); HashMap<Integer, Integer> integerIntegerHahsMap = new HashMap<Integer, Integer>(); candles.forEach(e->{ if(integerIntegerHahsMap.containsKey(e)){ integerIntegerHahsMap.put(e,integerIntegerHahsMap.get(e)+1); }else{ integerIntegerHahsMap.put(e,1); } }); ArrayList<Integer> integers = new ArrayList<>(); integerIntegerHahsMap.forEach((k,v)->{ integers.add(v); }); return integers.get(integers.size()-1); }
标签:integers,return,int,candles,元素,个数,integerIntegerHahsMap,数组,size From: https://www.cnblogs.com/liaowanzhong/p/18424989