首页 > 代码库 > LeetCode(14)Longest Common Prefix

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