2022-03-27 18:35:17 +08:00
|
|
|
<p>Write a function to find the longest common prefix string amongst an array of strings.</p>
|
|
|
|
|
|
|
|
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
|
|
|
|
|
|
|
|
<p> </p>
|
2023-12-09 18:42:21 +08:00
|
|
|
<p><strong class="example">Example 1:</strong></p>
|
2022-03-27 18:35:17 +08:00
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input:</strong> strs = ["flower","flow","flight"]
|
|
|
|
<strong>Output:</strong> "fl"
|
|
|
|
</pre>
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
2022-03-27 18:35:17 +08:00
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input:</strong> strs = ["dog","racecar","car"]
|
|
|
|
<strong>Output:</strong> ""
|
|
|
|
<strong>Explanation:</strong> There is no common prefix among the input strings.
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li><code>1 <= strs.length <= 200</code></li>
|
|
|
|
<li><code>0 <= strs[i].length <= 200</code></li>
|
2023-12-09 18:42:21 +08:00
|
|
|
<li><code>strs[i]</code> consists of only lowercase English letters.</li>
|
2022-03-27 18:35:17 +08:00
|
|
|
</ul>
|