[LeetCode][python3]0014. Longest Common Prefix

class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
if strs:
min_len=len(min(strs,key = len))
for i in range(min_len):
c=min(strs,key = len)[i]
for s in strs:
if s[i]!=c:
if i==0:
return ""
return min(strs,key = len)[0:i]
break
return min(strs,key = len)
else:
return ""
N2I -2020.03.18
class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
if not strs:return ""
m,M,i=min(strs),max(strs),0
for i in range (min(len(m),len(M))):
if m[i]!=M[i]:break
else:
i=i+1
return m[:i]
N2I -2020.03.18

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store