Lintcode78 Longest Common On Prefix solution 题解

【题目描述】

Given k strings, find the longest common prefix (LCP).

给k个字符串,求出他们的最长公共前缀(LCP)

【题目链接】

www.lintcode.com/en/problem/longest-common-prefix/

【题目解析】

解题思路是:先对整个String数组预处理一下,求一个最小长度(最长前缀肯定不能大于最小长度)。

然后以第0个字符串作为参照,从第1个字符串到最后一个字符串,对同一位置做判断,有不同字符串返回当前记录的字符串就行。

【参考答案】

www.jiuzhang.com/solutions/longest-common-prefix/

你可能感兴趣的:(Lintcode78 Longest Common On Prefix solution 题解)