Python DP solution


  • 0
    T
    def buildLookupTable(self,s,wordDict):
        lookupTable = []
        
        for i in range(len(s)+1):
            flag1 = True
            word = s[0:i]
            if word in wordDict:
                lookupTable.append(True)
                flag1 = False
            if (flag1):
                flag = True
                for j in range(i):
                    word2 = s[j:i]
                    if (word2 in wordDict) and (lookupTable[j] is True):
                        flag = False
                if flag:
                    lookupTable.append(False)
                else:
                    lookupTable.append(True)
        return (lookupTable[len(s)])

Log in to reply
 

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