class Solution(object):
def longestCommonPrefix(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
# 首先判断是否是空的字符串
if not strs:
return ""
s1=min(strs)
s2=max(strs)
for i,c in enumerate(s1):
if c!=s2[i]:
return s1[:i]
return s1
if __name__=='__main__':
A=Solution()
print(A.longestCommonPrefix(["flower","flow","flight"]))
最长公共前缀
最新推荐文章于 2021-02-07 23:36:10 发布