共计 278 个字符,预计需要花费 1 分钟才能阅读完成。
Write a function to find the longest common prefix string amongst an array of strings.
def lcp(self, str1, str2):
i = 0
while (i < len(str1) and i < len(str2)):
if str1[i] == str2[i]:
i = i+1
else:
break
return str1[:i]
# @return a string
def longestCommonPrefix(self, strs):
if not strs:
return ''
else:
return reduce(self.lcp,strs)
正文完
请博主喝杯咖啡吧!