Algorithm:
Using SubString { int beginPos; int freq = 1} to present sub string of input from beginPos to n.
Sort all SubString by desc. Complexity = n log n
Scan result one by one
If prev contains current, current.freq += 1
End Scan
So, the total time complexity is n log n + n
if count the string comparison, (n log n + n) * n / 2
space complexity: n * 2, depends on sorting algorithm
用楼主的例子解释
Input: abcab
所以,有5个SubString,不是所有的子串。每个SubString用一个数字表示,这样不用占空间
0: abcab
1: bcab
2: cab
3: ab
4:b
排序后
3:cab
1:bcab
4:b
0:abcab
3:ab