第三题可以用LinkedHashMap保证按照插入顺序 Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } LinkedHashMap<Integer, Integer> map = new LinkedHashMap<>(); for (int i = 0; i < n; i++) { int key = arr[i]; map.put(key,map.getOrDefault(key,0)+1); } int max = 0; for (Integer value : map.values()) { max = Math.max(max,value); } while (max >0){ for (Integer key : map.keySet()) { if (map.get(key)==max){ System.out.print(key+","); } } max--; }
点赞 评论

相关推荐

可以不说话:笔试a了3道半,今天说是挂了😭😭
投递汇丰科技等公司10个岗位
点赞 评论 收藏
分享
牛客网
牛客企业服务