problem
solution
option 1 - heap
- 先用一個hash table 紀錄每個數字與其出次數
- 用一個heap,並自定義比較的函數,將
{數字,出現次數 }
push into heap - heap pop
1 | class Solution { |
option 2 - bucket sorting
1 | class Solution { |
analysis
- option 1
- time complexity
O(nlogK)
- space complexity
O(n)
- time complexity
- option 2
- time complexity
O(n)
- space complexity
O(n)
- time complexity