有大佬帮忙看看第三题为什么ac 0%吗?
private static void find(String[] s,int k){ Map<String,Integer> map = new HashMap<>(); for(String s1:s){ if(map.containsKey(s1)){ map.put(s1,map.get(s1)+1); }else{ map.put(s1,1); } } PriorityQueue<String> priorityQueue = new PriorityQueue<>(new Comparator<String>() { @Override public int compare(String o1, String o2) { if(o1.charAt(0)!=o2.charAt(0)){ return o2.charAt(0)-o1.charAt(0); }else{ return o1.substring(1).compareTo(o2.substring(1)); } } }); for(String s2:map.keySet()){ String s1 = String.valueOf(map.get(s2))+s2; priorityQueue.add(s1); } get(k,priorityQueue); PriorityQueue<String> priorityQueue1 = new PriorityQueue<>(); for(String s2:map.keySet()){ String s1 = String.valueOf(map.get(s2))+s2; priorityQueue1.add(s1); } get(k,priorityQueue1); } private static void get(int k,PriorityQueue<String> priorityQueue){ for(int i=0;i<k;i++){ String s1 = priorityQueue.poll(); System.out.print(s1.substring(1,s1.length())); System.out.print(" "); System.out.print(s1.substring(0,1)); System.out.println(" "); } }
全部评论
(1) 回帖