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
Auf dieser Seite können Sie das Online-Video #14 Solving The Longest Common Prefix in Python mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Mirage 12 Dezember 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 30 Mal angesehen und es wurde von 0 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!