Python DP solution for large dict( like real dict) and short string


  • 0
    H
    class Solution:
        # @param s, a string
        # @param dict, a set of string
        # @return a boolean
        def wordBreak(self, s, dict):
            
            indict = [False]* len(s)
            for i in range(len(s)):
                for j in range(i+1):
                    if (j ==0 or indict[j-1]) and s[j:i+1] in dict:
                        indict[i] = True
             
            return indict[-1]

Log in to reply
 

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