Write a function to find the longest common prefix string amongst an array of strings.
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
string longestCommonPrefix(vector<string> &strs) {
string zero;
if (strs.empty())
return zero;
int maxlength = strs[0].size();
for (int i = 1;i!=strs.size();++i){
maxlength = min(maxlength,static_cast<int>(strs[i].size()));
for (int j = 0;j!=maxlength;++j){
if (strs[0][j]!=strs[i][j]){
maxlength = j;
break;
}
}
}
return strs[0].substr(0,maxlength);
}