class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
if strs == []:
return ''
length = len(strs)
tempres = ''
minlength = len(strs[0])
for thisstr in strs:
minlength = min(len(thisstr),minlength)
for i in range(minlength):
for j,thisstr in enumerate(strs):
if j == 0:
tempres += thisstr[i]
elif j <= length - 1:
if tempres[i] != thisstr[i]:
return tempres[:-1]
return tempres
Leetcode brushing record-14. El prefijo común más largo
Supongo que te gusta
Origin blog.csdn.net/weixin_41545780/article/details/105475317
Recomendado
Clasificación