How to find Longest Common Substring using C++

前端 未结 7 1960
轮回少年
轮回少年 2020-12-05 07:43

I searched online for a C++ Longest Common Substring implementation but failed to find a decent one. I need a LCS algorithm that returns the substring itself, so it\'s not j

7条回答
  •  再見小時候
    2020-12-05 08:37

    The answer is GENERALISED SUFFIX TREE. http://en.wikipedia.org/wiki/Generalised_suffix_tree

    You can build a generalised suffix tree with multiple string.

    Look at this http://en.wikipedia.org/wiki/Longest_common_substring_problem

    The Suffix tree can be built in O(n) time for each string, k*O(n) in total. K is total number of strings.

    So it's very quick to solve this problem.

提交回复
热议问题