<qiyuangong>692_Top_K_Frequent_Words_2.java
public List<String> topKFrequent(String[] words, int k) {
        Map<String, Integer> count = new HashMap();
        for (String word: words) {
            count.put(word, count.getOrDefault(word, 0) + 1);
        }
        PriorityQueue<String> heap = new PriorityQueue<String>(
                (w1, w2) -> count.get(w1).equals(count.get(w2)) ?
                w2.compareTo(w1) : count.get(w1) - count.get(w2) );

        for (String word: count.keySet()) {
            heap.offer(word);
            if (heap.size() > k) heap.poll();
        }

        List<String> ans = new ArrayList();
        while (!heap.isEmpty()) ans.add(heap.poll());
        Collections.reverse(ans);
        return ans;
    }
public List < String > var_1 ( String [ ] var_2 , int var_3 ) {
  Map < String , Integer > var_7 = new HashMap ( ) ;
  for ( String var_8 : var_2 ) {
    var_7 . put ( var_8 , var_7 . getOrDefault ( var_8 , 0 ) + 1 ) ;
  }
  PriorityQueue < String > var_19 = new PriorityQueue < String > ( ( var_14 , var_17 ) -> var_7 . get ( var_14 ) . equals ( var_7 . get ( var_17 ) ) ? var_17 . compareTo ( var_14 ) : var_7 . get ( var_14 ) - var_7 . get ( var_17 ) ) ;
  for ( String var_8 : var_7 . keySet ( ) ) {
    var_19 . offer ( var_8 ) ;
    if ( var_19 . size ( ) > var_3 ) var_19 . poll ( ) ;
  }
  List < String > var_26 = new ArrayList ( ) ;
  while ( ! var_19 . isEmpty ( ) ) var_26 . add ( var_19 . poll ( ) ) ;
  Collections . reverse ( var_26 ) ;
  return var_26 ;
}
