LeetCode交流

LeetCode1.9

2019-01-09  本文已影响0人  supermanwasd

Longest Common Prefix

class Solution:
    def longestCommonPrefix(self, strs):
        """
        :type strs: List[str]
        :rtype: str
        """
        if len(strs) == 0:
            return '' 
        res = ''
        strs = sorted(strs)
        for i in strs[0]:
            if strs[-1].startswith(res+i):
                res += i
            else:
                break
        return res
上一篇 下一篇

猜你喜欢

热点阅读