题目: Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.
题意:求所有字符串的最长公共前缀
想法:每个字符串都有同样的一个公共前缀,求最长的那个,从字符串容器中取第一个字符串将其每一个字符与其后的字符串依次进行对比即可,本题最后时间复杂度也能够通过,比较简单,属于基础的字符串处理题。
class Solution {
public:
string longestCommonPrefix(vector
& strs)
{
if(strs.size()==0)
return "";
string prefix = "";
for(int i=0;i