LeetCode1.9
2019-01-09 本文已影响0人
supermanwasd
Longest Common Prefix

class Solution:
def longestCommonPrefix(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
if len(strs) == 0:
return ''
res = ''
strs = sorted(strs)
for i in strs[0]:
if strs[-1].startswith(res+i):
res += i
else:
break
return res