class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
string = ''
if len(strs) != 0:
string = min(strs,key = lambda s:len(s))
end = len(string)
for s in strs:
i = end
while i >= 0:
if string[:i] == s[:i]:
end = i
break
else:
i -= 1
if i == -1:
return ''
return string[:end]
github项目地址:https://github.com/JockWang/LeetCode-Python