LeetCode(14)Longest Common Prefix

Posted 你瞅啥

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode(14)Longest Common Prefix相关的知识,希望对你有一定的参考价值。

题目如下:

Python代码:

def longestCommonPrefix(self, strs):
        """
        :type strs: List[str]
        :rtype: str
        """
        if not strs:
            return \'\'
        for i,letter_group in enumerate(zip(*strs)):
            if len(set(letter_group))>1:
                return strs[0][:i]
        else:
            return min(strs)

 

以上是关于LeetCode(14)Longest Common Prefix的主要内容,如果未能解决你的问题,请参考以下文章

leetcode14. longest common prefix

Leetcode 14. Longest Common Prefix

Leetcode 14 Longest Common Prefix

Leetcode14. Longest Common Prefix

LeetCode 14: Longest Common Prefix

leetcode 14. Longest Common Prefix