一天一道算法题之求最长公共前缀
##编写一个函数来求字符串数组的最长公共前缀
def longestCommonPrefix(self,strs:List[str]) ->str:
s = ''
for i in zip(*strs):
if len(set(i)) == 1:
s += 1
else:
break
return s
##这里来理解下zip函数的作用
wordsstr = ['flower','flow','flight']
for i in zip(*wordsstr):
print(i)
('f','f','f')
('l','l','l')
('o','o','i')
('w','w','g')