实例说明
示例 1:
输入: ["flower","flow","flight"]输出: "fl"
示例 2:
输入: ["dog","racecar","car"]输出: ""解释: 输入不存在公共前缀。
说明:
所有输入只包含小写字母 a-z
。
实现方法:
#include#include #include using namespace std;string longestCommonPrefix(vector & strs){string re="";if(strs.empty()) return re;if(strs.size()==1){ re+=strs.at(0); return re;}int jishu=0; int arrsize=strs.at(0).size(); for(int p=1;p strs.at(p).size()) arrsize=strs.at(p).size(); } for(int k=0,zm=0,jn=0;k =arrsize) break; } if(k==0) jishu=jn; else if(jn str;//vector ::iterator it; string a[3]={ "flower","flow","flight"};//string a[3]={"dog","racecar","car"};//string a="a";vector str;//str.push_back(a);//cout< < >putstr){str.push_back(putstr);}*/string bbbb=longestCommonPrefix(str);cout< <