there is a problem with the longest common prefix on leetcode. I want to solve it in a different way, but what I typed is:
fl
fl
flo
Why does print have three results?
class Solution:
def inter_prefix(self,strs=list,minPrefix=str):
if minPrefix == "": return minPrefix
for i in range(len(strs)):
mi = strs[i][:len(minPrefix)]
if minPrefix != mi:
minPrefix = minPrefix[:-1]
self.inter_prefix(strs, minPrefix)
print(minPrefix)
def longestCommonPrefix(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
if not strs: return ""
minPrefix = strs[0]
-sharp if len(strs) == 1:return (minPrefix)
for i in range(len(strs)):
if len(minPrefix) > len(strs[i]):
minPrefix = strs[i]
self.inter_prefix(strs,minPrefix)
if name ="_ _ main__":
Solution().longestCommonPrefix(["flower","flow","flight"])