# 最长公共前缀

<p>编写一个函数来查找字符串数组中的最长公共前缀。</p><p>如果不存在公共前缀，返回空字符串 <code>""</code>。</p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>strs = ["flower","flow","flight"]<strong><br />输出：</strong>"fl"</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>strs = ["dog","racecar","car"]<strong><br />输出：</strong>""<strong><br />解释：</strong>输入不存在公共前缀。</pre><p> </p><p><strong>提示：</strong></p><ul>	<li><code>0 <= strs.length <= 200</code></li>	<li><code>0 <= strs[i].length <= 200</code></li>	<li><code>strs[i]</code> 仅由小写英文字母组成</li></ul>

## template

```cpp
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;
	}
};
```

## 答案

```cpp

```

## 选项

### A

```cpp

```

### B

```cpp

```

### C

```cpp

```