Write a function to find the longest common prefix string amongst an array of strings.
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
if(strs.empty()) return "";
int num =INT_MAX;
bool flag =true;
int len =0;
for(auto t:strs){
if(t.size()<num) num=t.size();
}
while(len<num){
for(int i=1;i<strs.size()&&flag;i++){
if(strs[i][len]==strs[0][len]) continue;
flag = false;
}
if(!flag) break;
len++;
}
return strs[0].substr(0,len);
}
};