来源:leetcode
题目:编写一个函数来查找字符串数组中的最长公共前缀。如果不存在公共前缀,返回空字符串""。
解决:
#-*- coding:utf-8 -*-
class Solution(object):
def longestCommonPrefix(self, strs):
"""
:typestrs: List[str]
:rtype: str
"""
same_str=''
if not strsor str==['']:
return ''
s1 =min(strs)
s2 =max(strs)
if s1!='' and s2!='':
for i, jin enumerate(s1):
if j != s2[i]:
break
else:
same_str+=s2[i]
return same_str
else:
return ''
s=Solution()
print(s.longestCommonPrefix([输入测试列表]))