Write a function to find the longest common prefix string amongst an array of strings.
class Solution {
public:
string longestCommonPrefix(vector<string> &strs) {
string s;
if(strs.empty()){
return s;
}
int index=strs[0].size();
for(int i=1;i<strs.size();i++){
for(int j=0;j<index;j++){
if(strs[i][j]!=strs[0][j]){
index=j;
break;
}
}
}
s.assign(strs[0].begin(),strs[0].begin()+index);
return s;
}
};