class Solution(object): def isSamechar(self,strs,pos): if(len(strs[0])<=pos): return False else: for i in range(1,len(strs)): if len(strs[i])<=pos or strs[i][pos]!=strs[0][pos]: return False return True def longestCommon(self,strs,left ,right): if left==right: if isSamechar(self,strs,left): return strs[0][left] else: return "" mid=left+(right-left)/2 if(len(longestCommon(self,strs,left,mid))==(right-left)/2): return longestCommon(self,strs,left,mid)+longestCommon(self.strs,mid,right) else: return longestCommon(self,strs,left,mid) def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ res=longestCommon(self,strs,0,len(strs[0])) return res