problem
solution
option 1 - cheat
1 | class Solution { |
option 2 - heap
1 | class Solution { |
option 3 - histogram or hash table
1 | class Solution { |
option 4 - swap
不斷地交換,直到放到對的位置
1 | class Solution { |
analysis
- option 1
- time complexity
O(nlogn)
- space complexity
O(1)
- time complexity
- option 2
- time complexity
O(n)
- space complexity
O(k)
- time complexity
- option 3
- time complexity
O(n)
- space complexity
O(n)
- time complexity
- option 4
- time complexity
O(n)
- space complexity
O(1)
- time complexity