347. Top K Frequent Elements

Description

Here

Intuition

Intuitively, we can find a O(N * log(k)) soluton by using a priority queue.

However, we can use bucket sort to achieve O(N).

Steps:

  1. Count the frequency of elements.
  2. Put into List<List<Integer>> freqToElements, the index is the frequency
  3. Loop from the tail, add to the result list.

Pitfall

Solution

Solution

results matching ""

    No results matching ""