Suggestions - Python Solution works but time limit exceeds


  • 0
    B

    class Solution(object):
    #Brute Force
    def hasCommonLetter(self,s , t) :

        #print s , t
        slen=len(s)
        tlen=len(t)
        
        for i in range(slen):
            for j in range(tlen):
                #print s[i], t[j]
                if s[i]==t[j]:
                    return True
        
        return False
    
    def maxProduct(self, words):
        """
        :type words: List[str]
        :rtype: int
        """
        length =len(words)
        maxProd=0
        for i in range(length):
            #print words[i]
            j=i+1
            while j <length :
                #print words[i] , words[j]
                if self.hasCommonLetter(words[i] , words[j]) ==False:
                    calProd=len(words[i])*len(words[j])
                    if calProd> maxProd: maxProd=calProd
                j+=1
                
        return maxProd

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.