尋找一個(gè)字符串?dāng)?shù)組中的最長(zhǎng)公共子串
class Solution(object):
def longestCommonPrefix(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
if not strs:
return ''
#獲取最短和最長(zhǎng)的str
s1 = min(strs)
s2 = max(strs)
for i, c in enumerate(s1):
#不同院尔,截至i
if c != s2[i]:
return s1[:i]
return s1