problem
solution
option 1
用hash table 存下已出現的字串(排序過)及index
1 | class Solution { |
option 2
用字元加上出現次數編碼後當作hash table的key,放進hash table
例如:”eat” 編碼後 “a1e1t1”
1 | class Solution { |
analysis
- option 1
- time complexity
O(n*mlogm)
, m is the maximum of string - space complexity
O(n)
- time complexity
- option 2
- time complexity
O(n)
- space complexity
O(n)
- time complexity