解法一(32 ms 94.75%):
class Solution(object):
def longestCommonPrefix(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
if len(strs)==0:
return ""
L=[]
s=set()
count=0
for i in strs:
L.append(len(i))
length=min(L)
j=0
while j<length:
for i in range(len(strs)):
s.add(strs[i][j])
if len(s)==1:
s = set()
count+=1
j+=1
continue
else:
break
return strs[0][0:count]
网友评论