找到最短的字符串
已list[0]为标准,遍历list,加单个字符串右指针,不同即已到最长公共字串,返回
class Solution(object): def longestCommonPrefix(self, strs): if not strs: return "" if len(strs) == 1: return strs[0] #minl = min([len(x) for x in strs]) l=[] #最短字符串 for i in strs: l.append(len(i)) minl=min(l) end = 0 while end < minl: for i in range(1,len(strs)): #不同便已是最长 if strs[i][end]!= strs[i-1][end]: return strs[0][:end] end += 1 return strs[0][:end]