problem
solution
count sorting ,memory 會爆掉
option 1 - sorting
1 | class Solution { |
option 2 - hash table
1 | class Solution { |
option 3 - vote
1 | class Solution { |
analysis
- option 1 - sorting
- time complexity
O(nlogn)
- sort complexity
O(1)
- time complexity
- option 2 - hash table
- time complexity
O(n)
- space complexity
O(n)
- time complexity
- option 3 - vote
- time complexity
O(n)
- space complexity
O(1)
- time complexity