class Solution
{
public:
	string longestCommonPrefix(vector<string> &strs)
	{
		string lcp;
		if (strs.size() == 0)
			return lcp;
		int min_len = INT_MAX;
		int min_idx = 0;
		for (int i = 0; i < strs.size(); ++i)
		{
			auto &s = strs[i];
			if (s.size() < min_len)
			{
				min_len = s.size();
				min_idx = i;
			}
		}
		auto &smin = strs[min_idx];
		for (int i = 0; i < min_len; ++i)
		{
			char c = smin[i];
			int j;
			for (j = 0; j < strs.size(); ++j)
			{
				auto &cs = strs[j];
				if (c != cs[i])
					break;
			}
			if (j == strs.size())
				lcp += c;
			else
				break;
		}
		return lcp;
	}
};