字符串交集

Strings intersection

我有三个具有字符串值的变量。需要找到所有三条线之间最长的交点。像这样:

let str1 = 'abc123efg';
let str2 = 'c123efg';
let str3 = 'abcdefg';

// result -> 'efg'

然而问题的解决是使用4个for个循环。简而言之,我将绳子切成不同长度的片段,然后将它们与其他所有绳子进行比较。我不认为这是正确的做法。

请推荐一些关于该主题的书籍或文章。

应用设计用于处理多个序列的最长公共子串算法应该能让您找到它。

对于您的具体情况,请在线查找 "MLCS algorithm" 但是...

The multiple longest common subsequence problem (MLCS) is to find the longest subsequence shared between two or more strings. It is an NP-hard problem [35], with important applications in many fields, such as information retrieval and computational biology [3], [9], [42], [44]. For over 30 years, significant efforts have been made to find efficient algorithms for the MLCS problem. Many of them, however, address either the simplest case of MLCS of two strings, also known as the longest common subsequence (LCS) problem [24], [36], [39], [45], or the problem's special case of three strings [21], [22]. Although several methods have been proposed for the general case of any given number of strings [11], [22], [27], [29], they could benefit greatly from improving their computation times. A method that solves the general MLCS problem efficiently can be applied to many computational biology and computational genomics problems that deal with biological sequences [8], [28], [29], [43]. With the increasing volume of biological data and prevalent usage of computational sequence analysis tools, we expect that the general MLCS algorithm will have a significant impact on computational biology methods and their applications.

http://ieeexplore.ieee.org/document/5530316/