problem
solution
option 1 - sorting
1 | class Solution { |
option 2
1 | class Solution { |
unordered_set insert and serach 分攤後時間複雜度都是
O(1)
analysis
- option 1 - sorting
- time complexity
O(nlogn)
- space complexity
O(1)
- time complexity
- option 2
- time complexity
O(n)
- space complexity
O(n)
- time complexity