347. Top K Frequent Elements

Quick select

use quick select is too complex, this Q can be solved by bucket sort.

time: O(n)

space: O(m), map size

idea - use map to count, then gen a new array to do the quick select

just the compare condition becomes like this:

Random Pivot

Last updated

Was this helpful?