class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
if len(strs)==0:
return ''
if len(strs)==1:
return strs[0]
s=''
for j in range(len(strs[0])):
for i in range(1,len(strs)):
if len(strs[i])>=j+1:
if strs[i][j]!=strs[0][j]:
return s
else:
return s
s+=strs[0][j]
return s
14. Longest Common Prefix
最新推荐文章于 2024-04-07 06:08:03 发布