7-line Python DP


  • 0
    Z

    Original title was "Naive python solution.. looks like Greedy?"

    Keeping track of possible start indices.

    def wordBreak(self, s, wordDict):
        starts = [0]
        for i in range(len(s)):
            for j in starts:
                if s[j:i+1] in wordDict:
                    starts.append(i+1)
                    break
        return starts[-1] == len(s)

Log in to reply
 

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