Write a function to find the longest common prefix string amongst an array of strings.
#include <string>
#include <vector>
using namespace std;
class Solution {
public:
string longestCommonPrefix(vector<string> &strs) {
if(strs.empty()){
string emptyStr;
return emptyStr;
}
string k = strs[0];
for(int i = 1; i < strs.size(); ++i){
k = GetCommonPrefix(k, strs[i]);
}
return k;
}
string GetCommonPrefix(const string &a, const string &b){
int len = a.size() < b.size() ? a.size():b.size();
string result;
for(int i = 0; i < len; ++i){
if(a[i] == b[i]){
result.push_back(a[i]);
}
else{
break;
}
}
return result;
}
};
int main(){
return 0;
}