14. Longest Common Prefix[E]

题目

Write a function to find the longest common prefix string amongst an array of strings.
If there is no common prefix,return an empty string "".
Example1:
Input:
Output:

思路

由于本题的要求的是找到最长公共前缀,必须以一个字符串作为基准寻找,一个加快运行速度的办法就是找到长度最短的字符串,作为参照去匹配后面的字符串。
写代码充分运用公共(以长度最短字符串作为基准)和前缀(利用子字符串方法)两个关键字。

C++

Python

猜你喜欢

转载自www.cnblogs.com/Jessey-Ge/p/10993475.html