class Solution:
def longestCommonPrefix(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
if len(strs)==0:
return ''
x=0
y=0
while x<len(strs) and y<len(strs[x]):
if x==0:
word=strs[x][y]
else:
if strs[x][y]!=word:
break
if x==len(strs)-1:
y+=1
x=0
else:
x+=1
return strs[x][:y]
python算法:最长公共前缀
最新推荐文章于 2022-09-30 22:07:37 发布