class Solution:
# @param {string[]} strs
# @return {string}
def longestCommonPrefix(self, strs):
if strs == []:
return ''
if len(strs)==1:
return strs[0]
for i in range(1,len(strs)):
if len(strs[0])>len(strs[i]):
mLen=len(strs[i])
else:
mLen=len(strs[0])
if mLen==0:
return ''
strs[0]=strs[0][:mLen]
for j in range(mLen):
if strs[0][j] != strs[i][j]:
strs[0] = strs[0][0:j]
break
return strs[0]
Longest Common Prefix
最新推荐文章于 2024-02-18 12:25:05 发布