The minimum length of the character in the first string, determines whether all subsequent recursive string prefix also contain, if contained, are added to the Result result, there is a character string containing no iteration directly returns the result code is implemented as follows:
classSolution(object):deflongestCommonPrefix(self, strs):"""
:type strs: List[str]
:rtype: str
"""
result =''if strs ==[]or''in strs:return''else:
N =len(strs[0])#更新最短字符串的长度for s in strs:iflen(s)< N:
N =len(s)#迭代过程for j inrange(N):
tmp = strs[0][j]for i inrange(len(strs)):
t = strs[i][j]if tmp != t:return result
result += strs[0][j]return result