#14 Solving The Longest Common Prefix in Python

Pubblicato il: 12 dicembre 2020
sul canale di: Mirage
30
0

Writing a Python function that finds the longest common prefix in an array of strings. Satisfying conditions and returning an empty string " " if nothing is in the array.
This is my python code below (for you to copy and paste):
def longestCommonPrefix(self, strs):
if(not strs):
return ""
if(len(strs)==1):
return strs[0]
res=""
strs.sort()
a=strs[0]
b=strs[len(strs)-1]
for i in range(len(a)):
if(a[i]==b[i]):
res+=a[i]
else:
break
return res


In questa pagina del sito puoi guardare il video online #14 Solving The Longest Common Prefix in Python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Mirage 12 dicembre 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 30 volte e gli è piaciuto 0 spettatori. Buona visione!