Class Solution

java.lang.Object
g0001_0100.s0014_longest_common_prefix.Solution

public class Solution extends Object
14 - Longest Common Prefix.<p>Easy</p> <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>&quot;&quot;</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> strs = [&ldquo;flower&rdquo;,&ldquo;flow&rdquo;,&ldquo;flight&rdquo;]</p> <p><strong>Output:</strong> &ldquo;fl&rdquo;</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> strs = [&ldquo;dog&rdquo;,&ldquo;racecar&rdquo;,&ldquo;car&rdquo;]</p> <p><strong>Output:</strong> &quot;&quot;</p> <p><strong>Explanation:</strong> There is no common prefix among the input strings.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= strs.length <= 200</code></li> <li><code>0 <= strs[i].length <= 200</code></li> <li><code>strs[i]</code> consists of only lower-case English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • longestCommonPrefix

      public String longestCommonPrefix(String[] strs)