Write a function to find the longest common prefix string amongst an array of strings.
class Solution {
public:
string longestCommonPrefix(vector<string> &strs) {
string result;
if(strs.size()==0) return result;
int m=strs.size(),n=strs[0].size();
for(int j=0;j<n;j++){
char temp=strs[0][j];
bool addChar=true;
for(int i=1;i<m;i++){
if(strs[i].size()<=j||strs[i][j]!=temp) {
addChar=false;
break;
}
}
if(addChar) result.append(1,temp);
else break;
}
return result;
}
};