class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
map<string,int> mmap;
for(int i = 0;i<strs.size();++i)
{
for(int j = 1;j<=strs[i].size();j++){
string temp = strs[i].substr(0,j);
if(mmap.find(temp) == mmap.end())
mmap.insert(make_pair(temp,1));
else mmap[temp]++;
}
}
int mmax = numeric_limits<int>::min();
string str;
for(auto item:mmap)
{
if(item.second == strs.size())
{
if(mmax < (int)item.first.size())
{
mmax = item.first.size();
str = item.first;
}
}
}
return str;
}
};