leetcode-算法-14 Python

觉得不是很满意,可能是因为题目就这样,只能做一些修修补补的工作

Python2.7

class Solution(object):
    def longestCommonPrefix(self, strs):
        """
        :type strs: List[str]
        :rtype: str
        """
        if len(strs) == 0:
            return ""

        return_list = ""
        min_len = min([len(x) for x in strs])

        for i in range(min_len+1):
            if i < min_len and all(strs[0][i] == x[i] for x in strs):
                continue

            return_list = strs[0][:i]
            break
        return return_list

你可能感兴趣的:(leetcode)