class Solution:
def longestCommonPrefix(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
if len(strs) == 0:
return ''
tmp = strs[0]
for i in range(1, len(strs)):
j = 0
while j < min(len(tmp), len(strs[i])):
if tmp[j] == strs[i][j]:
j += 1
continue
else:
if j == 0:
return ''
else:
break
tmp = tmp[0:j]
return tmp
Python, LeetCode, 14. 最长公共前缀
最新推荐文章于 2022-03-09 17:12:06 发布