相关疑难解决方法(0)

找到两个字符串之间的公共子串

我想比较2个字符串并保持匹配,在比较失败的地方分开.

所以,如果我有2个字符串 -

string1 = apples
string2 = appleses

answer = apples
Run Code Online (Sandbox Code Playgroud)

另一个例子,因为字符串可能有多个单词.

string1 = apple pie available
string2 = apple pies

answer = apple pie
Run Code Online (Sandbox Code Playgroud)

我确信有一种简单的Python方法可以做到这一点,但我无法解决,任何帮助和解释都表示赞赏.

python string algorithm dynamic-programming time-complexity

54
推荐指数
7
解决办法
7万
查看次数