Longest Common Prefix
Question
Answer
solution:this code without algorithm is done by myself.
class Solution(object):
def longestCommonPrefix(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
if not strs:
return ""
cprefix = strs[0]
common = [cprefix[0:x] for x in xrange(len(cprefix)+1,0,-1)]
for i in common:
lcommon = True
for s in strs:
if i in s[0:len(i)]:
continue
else:
lcommon = False
break
if lcommon == True:
return i
return ""Knowledge:
Last updated