def longestCommonPrefix(strs):
if len(strs)==0:
return ''
elif len(strs)==1:
return strs[0]
else:
b=sorted(strs,key=lambda x:len(x))
s=''
s1=b[0]
for i,v in enumerate(s1):
l = []
for j in b[1:]:
l.append(v==j[i])
if all(l):
s+=v
else:
break
return s
转载于:https://www.cnblogs.com/zhangtianxia/p/9033575.html