最长公共前缀(14)

法一:

class
Solution: def longestCommonPrefix(self, strs: List[str]) -> str: if not strs: return '' str_min = min(strs) str_max = max(strs) for i in range(len(str_min)): if str_min[i] != str_max[i]: return str_min[:i] return str_min 法二:
class Solution:
    def longestCommonPrefix(self, strs: List[str]) -> str:
    ret = ''
    for i in zip(*strs):
    if len(set(i)) ==1:
    ret+=i[0]
    else:
    break
    return ret
 

 

posted on 2020-07-30 11:32  不要挡着我晒太阳  阅读(89)  评论(0编辑  收藏  举报

导航