lecode(2)

leetcode 找最長的公共子字符串前缀
class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
res = “”
right = 1
len1 = len(strs)
if len1 == 0:
return res
start = strs[0]
while right<=len(start):
for i in strs:
if start[0:right] != i[0:right]:
return res
if len(res) < right:
res = start[:right]
right+=1
return res

你可能感兴趣的:(lecode(2))