<qiyuangong>347_Top_K_Frequent_Elements_1.java
public List<Integer> topKFrequent(int[] nums, int k) {
    HashMap<Integer, Integer> count = new HashMap();
    for (int n: nums) {
      count.put(n, count.getOrDefault(n, 0) + 1);
    }

    PriorityQueue<Integer> heap =
            new PriorityQueue<Integer>((n1, n2) -> count.get(n1) - count.get(n2));

    for (int n: count.keySet()) {
      heap.add(n);
      if (heap.size() > k)
        heap.poll();
    }

    List<Integer> top_k = new LinkedList();
    while (!heap.isEmpty())
      top_k.add(heap.poll());
    Collections.reverse(top_k);
    return top_k;
  }
public List < Integer > var_1 ( int [ ] var_2 , int var_3 ) {
  HashMap < Integer , Integer > var_5 = new HashMap ( ) ;
  for ( int var_6 : var_2 ) {
    var_5 . put ( var_6 , var_5 . getOrDefault ( var_6 , 0 ) + 1 ) ;
  }
  PriorityQueue < Integer > var_15 = new PriorityQueue < Integer > ( ( var_13 , var_14 ) -> var_5 . get ( var_13 ) - var_5 . get ( var_14 ) ) ;
  for ( int var_6 : var_5 . keySet ( ) ) {
    var_15 . add ( var_6 ) ;
    if ( var_15 . size ( ) > var_3 ) var_15 . poll ( ) ;
  }
  List < Integer > var_22 = new LinkedList ( ) ;
  while ( ! var_15 . isEmpty ( ) ) var_22 . add ( var_15 . poll ( ) ) ;
  Collections . reverse ( var_22 ) ;
  return var_22 ;
}
